home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / 68000dsm.cq / 68000dsm.c
Encoding:
Text File  |  1985-11-20  |  134.9 KB  |  4,310 lines

  1. Article 2660 (70 more) in net.sources:
  2. From: jmc@inset.UUCP (John Collins)
  3. Subject: 68000 Disassembler
  4. Message-ID: <658@inset.UUCP>
  5. Date: 15 Aug 85 23:11:30 GMT
  6. Date-Received: 24 Aug 85 05:01:10 GMT
  7. Reply-To: jmc@inset.UUCP (John Collins)
  8. Organization: --- NONE ---
  9. Lines: 4303
  10. Xpath: icdoc ivax
  11.  
  12. --MORE--(0%)
  13. This is the 68000 disassembler mentioned on the net.
  14. It is not my final version by any means, but I have found it extremely
  15. useful and it represents severl weeks' work.
  16.  
  17.         John Collins.
  18.  
  19. You should get the following files:
  20.  
  21.         doc             - MM macros
  22.         makefile
  23.         unc.h
  24.         alloc.c
  25.         file.c
  26.         heur.c
  27.         iset.c
  28.         libmtch.c
  29.         main.c
  30.         prin.c
  31.         robj.c
  32.  
  33. To extract /bin/sh the remainder of the file after the next line
  34. ------------------------------cut here------------------------------
  35.  
  36. # To unbundle, sh this file
  37. echo doc 1>&2
  38. sed 's/.//' >doc <<'//GO.SYSIN DD doc'
  39. -.\"/*% nroff -cm -rL72 %|epson|spr -f plain.a -h uncdoc -w
  40. -.nr Hb 7
  41. -.nr Hs 3
  42. -.ds HF 3 3 3 3 3 3 3
  43. -.nr Hu 5
  44. -.nr Hc 1
  45. -.SA 1
  46. -.PH "''A Disassembler''"
  47. -.PF "'Issue %I%'- Page \\\\nP -'%G%'"
  48. -.H 1 "Introduction"
  49. -This document describes the first release of a disassembler for UNIX
  50. -executable files.
  51. -The key features are:
  52. -.AL
  53. -.LI
  54. -For object files the output can be assembled to generate the same
  55. -object module, (apart from minor variations in symbol table ordering) as the
  56. -input.
  57. -.LI
  58. -For stripped executable files object modules and libraries may be scanned,
  59. -modules in the main input identified and the appropriate names automatically
  60. -inserted into the output.
  61. -.LI
  62. -An option is available to convert most non-global names into local symbols,
  63. -which cuts down the symbols in the generated assembler file.
  64. -.LI
  65. -The disassembler copes reasonably with modules merged with the
  66. -.B "-r"
  67. -option to
  68. -.B "ld" ,
  69. -generating a warning message as to the number of modules involved.
  70. -.LE
  71. -.P
  72. -At present this is available forcertain Motorola 68000 ports of UNIX
  73. -System III and System V. Dependencies on
  74. -.AL a
  75. -.LI
  76. -Instruction set.
  77. -.LI
  78. -Object module format.
  79. -.LI
  80. -Library module format.
  81. -.LI
  82. -Assembler output format.
  83. -.LE
  84. -.P
  85. -are hopefully sufficiently localised to make the product useful as a
  86. -basis for other disassemblers for other versions of UNIX.
  87. -.P
  88. -The product is thus distributed in source form at present.
  89. -.H 1 "Use"
  90. -The disassembler is run by entering:
  91. -.DS I
  92. -unc mainfile lib1 lib2 ...
  93. -.DE
  94. -.P
  95. -The first named file is the file to be disassembled, which should be
  96. -a single file, either an object module, a (possibly stripped) executable
  97. -file, or a library member. Library members are designated using a
  98. -parenthesis notation, thus:
  99. -.DS I
  100. -unc '/lib/libc.a(printf.o)'
  101. -.DE
  102. -.P
  103. -It is usually necessary to escape the arguments in this case to prevent
  104. -misinterpretation by the shell. Libraries in standard places such as
  105. -.I "/lib"
  106. -and
  107. -.I "/usr/lib"
  108. -may be specified in the same way as to
  109. -.B "ld" ,
  110. -thus
  111. -.DS I
  112. -unc '-lc(printf.o)'
  113. -unc '-lcurses(wmove.o)'
  114. -.DE
  115. -.P
  116. -As an additional facility, the list of directories searched for
  117. -libraries may be varied by setting the environment variable
  118. -.B "LDPATH" ,
  119. -which is interpreted similarly to the shell
  120. -.B "PATH"
  121. -variable, and of course defaults to
  122. -.DS I
  123. -LDPATH=/lib:/usr/lib
  124. -.DE
  125. -.P
  126. -As a further facility, the insertion of
  127. -.B "lib"
  128. -before and
  129. -.B ".a"
  130. -after the argument may be suppressed by using a capital
  131. -.B "-L"
  132. -argument, thus to print out the assembler for
  133. -.I "/lib/crt0.o" ,
  134. -then the command
  135. -.DS I
  136. -unc -Lcrt0.o
  137. -.DE
  138. -.P
  139. -should have the desired effect.
  140. -.P
  141. -Second and subsequent file arguments are only referenced for stripped
  142. -executable files, and may consist of single object files and library
  143. -members, using the same syntax as before, or whole libraries of object
  144. -files, thus:
  145. -.DS I
  146. -unc strippedfile -Lcrt0.o -lcurses -ltermcap '-lm(sqrt.o)' -lc
  147. -.DE
  148. -.P
  149. -It is advisable to make some efort to put the libraries to be searched
  150. -in the order in which they were originally loaded. This is because the
  151. -search for each module starts where the previously matched module ended.
  152. -However, no harm is done if this rule is not adhered to apart from
  153. -increased execution time except in the rare cases where the disassembler
  154. -is confused by object modules which are very nearly similar.
  155. -.H 1 "Additional options"
  156. -The following options are available to modify the behaviour of the
  157. -disassembler.
  158. -.VL 15 2
  159. -.LI "-o file"
  160. -Causes output to be sent to the specified file instead of the standard
  161. -output.
  162. -.LI "-t prefix"
  163. -Causes temporary files to be created with the given prefix. The default
  164. -prefix is
  165. -.B "split" ,
  166. -thus causing two temporary files to be created with this prefix in the
  167. -current directory. If it is desired, for example, to create the files as
  168. -.B "/tmp/xx*" ,
  169. -then the argument
  170. -.B "-t /tmp/xx"
  171. -should be given. Note that the temporary files may be very large as a
  172. -complete map of the text and data segments is generated.
  173. -.LI "-a"
  174. -Suppresses the generation of non-global absolute symbols from the
  175. -output. This saves output from C compilations without any obvious
  176. -problems, but the symbols are by default included in the name of
  177. -producing as nearly identical output as possible to the original source.
  178. -.LI "-s"
  179. -Causes an additional scan to take place where all possible labels are
  180. -replaced by local symbols. The local symbols are inserted in strictly
  181. -ascending order, starting at 1.
  182. -.LI "-v"
  183. -Causes a blow-by-blow account of activities to be output on the standard
  184. -error.
  185. -.LE
  186. -.H 1 "Diagnostics etc"
  187. -Truncated or garbled object and library files usually cause processing
  188. -to stop with an explanatory message.
  189. -.P
  190. -The only other kinds of message are some passing warnings concerning
  191. -obscure constructs not handled, such as the relocation of byte fields,
  192. -or the relocation of overlapping fields. Occasionally a message
  193. -.DS I
  194. -Library clash: message
  195. -.DE
  196. -.P
  197. -may appear and processing cease. This message is found where at a late
  198. -stage in processing libraries, the program discovers that due to the
  199. -extreme similarity of two or more library members, it has come to the
  200. -wrong conclusion about which one to use. The remedy here is to spell out
  201. -to the program which members to take in which order.
  202. -.H 1 "Future development"
  203. -In the future it is hoped to devise ways of making the disassembler
  204. -independent of all the above-mentioned version dependencies, by first
  205. -reading a files defining these things. This will probably be applied
  206. -after the Common Object Format becomes more standard.
  207. -.P
  208. -In the long term it would be desirable and useful to enhance the product
  209. -to produce compilable C in addition to assemblable assembler. Stages in
  210. -the process are seen as follows:
  211. -.AL
  212. -.LI
  213. -Better identification of basic blocks in the code. Switch statements are
  214. -a major problem here, as are constant data held in the text segment.
  215. -.LI
  216. -Marrying of data to the corresponding text. It is in various places hard
  217. -to divorce static references "on the fly" (e.g. strings, and switch
  218. -lists in some implementations) from static at the head of a module. This
  219. -is part of the problem of identifying basic blocks.
  220. -.LI
  221. -Compilation of header files to work out structure references within the
  222. -text. At this stage some interaction may be needed.
  223. -.LE
  224. -.P
  225. -Meanwhile the product is one which is a useful tool to the author in its
  226. -present form. Comments and suggestions as to the most practical method
  227. -of improving the product in the ways suggested or in other ways would be
  228. -gratefully considered.
  229. //GO.SYSIN DD doc
  230. echo makefile 1>&2
  231. sed 's/.//' >makefile <<'//GO.SYSIN DD makefile'
  232. -CFLAGS=-v -OB
  233. -OBJS=alloc.o file.o libmtch.o robj.o iset.o prin.o heur.o main.o
  234. -
  235. -unc:   $(OBJS)
  236. -       cc -o unc $(OBJS)
  237. -
  238. -$(OBJS):       unc.h
  239. //GO.SYSIN DD makefile
  240. echo unc.h 1>&2
  241. sed 's/.//' >unc.h <<'//GO.SYSIN DD unc.h'
  242. -/*
  243. - *     SCCS:   @(#)unc.h       1.2     11/2/84 1421:02
  244. - *     Header file for uncompile program.
  245. - *
  246. - ***********************************************************************
  247. - *     This software is copyright of
  248. - *
  249. - *             John M Collins
  250. - *             47 Cedarwood Drive
  251. - *             St Albans
  252. - *             Herts, AL4 0DN
  253. - *             England                 +44 727 57267
  254. - *
  255. - *     and is released into the public domain on the following conditions:
  256. - *
  257. - *             1.  No free maintenance will be guaranteed.
  258. - *             2.  Nothing may be based on this software without
  259. - *                 acknowledgement, including incorporation of this
  260. - *                 notice.
  261. - *
  262. - *     Notwithstanding the above, the author welcomes correspondence and bug
  263. - *     fixes.
  264. - ***********************************************************************
  265. - */
  266. -
  267. -#define        MAXCHARS        50
  268. -#define        HASHMOD         97
  269. -
  270. -/*
  271. - *     The following structure is used to keep track of symbols.
  272. - */
  273. -
  274. -struct symstr  {
  275. -       struct  symstr  *s_next;                /*  Next in hash chain  */
  276. -       struct  symstr  *s_link;                /*  Next in duplicate labels */
  277. -       unsigned        s_type  :  3;           /*  Symbol type  */
  278. -       unsigned        s_newsym:  1;           /*  A new symbol  */
  279. -       unsigned        s_invent:  1;           /*  Invented symbol  */
  280. -       unsigned        s_glob  :  1;           /*  Global symbol  */
  281. -       long            s_value;                /*  Value if defined  */
  282. -       short           s_defs;                 /*  Defined count  */
  283. -       short           s_used;                 /*  Used count  */
  284. -       unsigned short  s_lsymb;                /*  Local symbol  */
  285. -       char            s_name[1];              /*  Chars of name null term */
  286. -};
  287. -
  288. -typedef        struct  symstr  *symbol;
  289. -
  290. -symbol symbhash[HASHMOD];
  291. -
  292. -typedef        struct  {
  293. -       int     ef_t;                   /*  Text file fd  */
  294. -       int     ef_d;                   /* Data file fd  */
  295. -       long    ef_entry;               /*  Entry point  */
  296. -       long    ef_tsize;               /*  Text size  */
  297. -       long    ef_dsize;               /*  Data size  */
  298. -       long    ef_bsize;               /*  Bss size  */
  299. -       long    ef_end;                 /*  End of it all  */
  300. -       long    ef_tbase;               /*  Text base  */
  301. -       long    ef_dbase;               /*  Data base  */
  302. -       long    ef_bbase;               /*  Bss base  */
  303. -       int     ef_stcnt;               /*  Number of symbols  */
  304. -       int     ef_stmax;               /*  Max number of symbols  */
  305. -       symbol  *ef_stvec;              /*  Symbol vector  */
  306. -}  ef_fids;
  307. -
  308. -typedef        ef_fids *ef_fid;
  309. -
  310. -/*
  311. - *     Description of word in text file.  This entry is held in the place
  312. - *     corresponding to the address in the text file.
  313. - */
  314. -
  315. -typedef        struct  {
  316. -       unsigned  short t_contents;             /*  Actual contents  */
  317. -       unsigned  short t_iindex;               /*  Index in table  */
  318. -       unsigned        t_type  :  2;           /*  Type  */
  319. -       unsigned        t_vins  :  1;           /*  Valid instruction  */
  320. -       unsigned        t_bdest :  1;           /*  Is branch dest  */
  321. -       unsigned        t_gbdest:  1;           /*  Is global dest  */
  322. -       unsigned        t_dref  :  1;           /*  Refered to in data  */
  323. -       unsigned        t_bchtyp:  2;           /*  Branch type  */
  324. -       unsigned        t_lng   :  3;           /*  Length in words  */
  325. -       unsigned        t_reloc :  2;           /*  Relocatable  */
  326. -       unsigned        t_rptr  :  2;           /*  Where relocated  */
  327. -       unsigned        t_rdisp :  1;           /*  Relocatable displacement */
  328. -       unsigned        t_isrel :  1;           /*  Relocated  */
  329. -       unsigned        t_amap  :  1;           /*  Worked out  */
  330. -       symbol          t_relsymb;              /*  Relocation symbol  */
  331. -       long            t_reldisp;              *  Offset + or - from symb */
  332. -       symbol          t_lab;                  /*  Label  */
  333. -       unsigned  short t_lsymb;                /*  Local symbol  */
  334. -       long            t_reflo;                /*  Lowest place referred  */
  335. -       long            t_refhi;                /*  Highest place referred  */
  336. -       unsigned  short t_match;                /*  Lib match lng  */
  337. -}  t_entry;
  338. -
  339. -/*
  340. - *     Types ......
  341. - */
  342. -
  343. -#define        T_UNKNOWN       0
  344. -#define        T_BEGIN         1
  345. -#define        T_CONT          2
  346. -
  347. -#define        R_NONE          0               /*  No relocation  */
  348. -#define        R_BYTE          1               /*  Byte relocation  */
  349. -#define        R_WORD          2               /*  Word relocation  */
  350. -#define        R_LONG          3               /*  Long relocation  */
  351. -
  352. -/*
  353. - *     Branch types.
  354. - */
  355. -
  356. -#define        T_NOBR          0
  357. -#define        T_CONDBR        1
  358. -#define        T_UNBR          2
  359. -#define        T_JSR           3
  360. -
  361. -typedef        struct  {
  362. -       unsigned  char  d_contents;             /*  Actual contents  */
  363. -       unsigned        d_type  :  4;           /*  Data type  */
  364. -       unsigned        d_reloc :  2;           /*  Relocatable  */
  365. -       unsigned        d_rptr  :  2;           /*  Where relocated  */
  366. -       short           d_lng;                  /*  Length -ve for D_CONT */
  367. -       symbol          d_relsymb;              /*  Relocation symbol  */
  368. -       long            d_reldisp;              /*  Offset + or - from symb */
  369. -       symbol          d_lab;                  /*  Label  */
  370. -}  d_entry;
  371. -
  372. -/*
  373. - *     Data types.
  374. - */
  375. -
  376. -#define        D_ASC           0               /*  Ascii chars  */
  377. -#define        D_ASCZ          1               /*  Null-term ascii  */
  378. -#define        D_BYTE          2               /*  Decimal bytes  */
  379. -#define        D_WORD          3               /*  Words  */
  380. -#define        D_LONG          4               /*  Longs  */
  381. -#define        D_ADDR         5               /*  Address pointer  */
  382. -#define        D_CONT          6               /*  Continuation of last  */
  383. -
  384. -/*
  385. - *     'Common' items.
  386. - */
  387. -
  388. -struct commit  {
  389. -       symbol  *c_symb;                /*  List of symbols  */
  390. -       int     c_int;                  /*  Current number  */
  391. -       int     c_max;                  /*  Maximum  */
  392. -};
  393. -
  394. -/*
  395. - *     Library file description.
  396. - */
  397. -
  398. -struct libit   {
  399. -       int     lf_fd;                  /*  File descriptor  */
  400. -       long    lf_offset;              /*  Offset of current file  */
  401. -       long    lf_next;                /*  Offset of next file  */
  402. -       char    lf_name[14];            /*  Name of item  */
  403. -};
  404. //GO.SYSIN DD unc.h
  405. echo alloc.c 1>&2
  406. sed 's/.//' >alloc.c <<'//GO.SYSIN DD alloc.c'
  407. -/*
  408. - *     SCCS:   @(#)alloc.c     1.2     11/2/84 14:17:20
  409. - *     Allocate space etc.
  410. - *
  411. - ***********************************************************************
  412. - *     This software is copyright of
  413. - *
  414. - *             John M Collins
  415. - *             47 Cedarwood Drive
  416. - *             St Albans
  417. - *             Herts, AL4 0DN
  418. - *             England                 +44 727 57267
  419. - *
  420. - *     and is released into the public domain on the following conditions:
  421. - *
  422. - *             1.  No free maintenance will be guaranteed.
  423. - *             2.  Nothing may be based on this software without
  424. - *                 acknowledgement, including incorporation of this
  425. - *                 notice.
  426. - *
  427. - *     Notwithstanding the above, the author welcomes correspondence and bug
  428. - *     fixes.
  429. - ***********************************************************************
  430. - */
  431. -
  432. -#include <stdio.h>
  433. -#include <a.out.h>
  434. -#include <setjmp.h>
  435. -#include "unc.h"
  436. -
  437. -#define        STINC   10
  438. -
  439. -char   *malloc(), *realloc();
  440. -char   *strncpy();
  441. -void   gette(), getde(), setde(), putte(), putde();
  442. -void   unimpl();
  443. -long   gettw();
  444. -
  445. -ef_fids        mainfile;
  446. -
  447. -/*
  448. - *     Oops! out of memory.....
  449. - */
  450. -
  451. void   nomem()
  452. -{
  453. -       (void) fprintf(stderr, "Sorry - run out of memory\n");
  454. -       exit(255);
  455. -}
  456. -
  457. -/*
  458. - *     Look up hash value of symbol.
  459. - */
  460. -
  461. -unsigned  shash(str)
  462. -register  char *str;
  463. -{
  464. -       register  unsigned  result = 0;
  465. -       register  int   cnt = 0;
  466. -       
  467. -       while  (*str  &&  cnt < MAXCHARS)  {
  468. -               result += *str++;
  469. -               cnt++;
  470. -       }
  471. -       return  result % HASHMOD;
  472. -}
  473. -
  474. -/*
  475. - *     Look up hash value of symbol, possibly allocating a new symbol.
  476. - */
  477. -
  478. -symbol lookup(str)
  479. -char   *str;
  480. -{
  481. -       register  symbol  res, *pp;
  482. -       register  int   len;
  483. -       
  484. -       pp = &symbhash[shash(str)];
  485. -       res = *pp;
  486. -       while  (res != NULL)  {
  487. -               if  (strncmp(res->s_name, str, MAXCHARS) == 0)
  488. -                       return  res;
  489. -               pp = &res->s_next;
  490. -               res = *pp;
  491. -       }
  492. -       for  (len = 0;  len < MAXCHARS;  len++)
  493. -               if  (str[len] == '\0')
  494. -                       break;
  495. -       len++;
  496. -       res = (symbol) malloc(sizeof(struct symstr) + len);
  497. -       if  (res == NULL)
  498. -               nomem();
  499. -       *pp = res;
  500. -       res->s_next = NULL;
  501. -       (void) strncpy(res->s_name, str, len);
  502. -       res->s_name[len] = '\0';                /*  Null-terminate  */
  503. -       res->s_newsym = 1;
  504. -       res->s_glob = 0;
  505. -       res->s_invent = 0;
  506. -       res->s_link = NULL;
  507. -       res->s_used = 0;
  508. -       res->s_defs = 0;
  509. -       res->s_lsymb = 0;
  510. -       return  res;
  511. -}
  512. -
  513. -/*
  514. - *     Invent a symbol, making sure that we don't know it.
  515. - */
  516. -
  517. -symbol inventsymb(prefix)
  518. -char   *prefix;
  519. -{
  520. -       static  int  nsymb = 0;
  521. -       char    schars[10];
  522. -       register  symbol  res;
  523. -       
  524. -       do      (void) sprintf(schars, "%s%d", prefix, ++nsymb);
  525. -       while  (!(res = lookup(schars))->s_newsym);
  526. -       
  527. -       res->s_newsym = 0;
  528. -       res->s_invent = 1;
  529. -       return  res;
  530. -}
  531. -        
  532. -/*
  533. - *     Reallocate symboltable.
  534. - */
  535. -
  536. -void   reallst(outf)
  537. -register  ef_fid  outf;
  538. -{
  539. -       outf->ef_stmax += STINC;
  540. -       if  (outf->ef_stvec == NULL)
  541. -               outf->ef_stvec = (symbol *) malloc(outf->ef_stmax * sizeof(symbol));
  542. -       else
  543. -               outf->ef_stvec = (symbol *) realloc(outf->ef_stvec,
  544. -                                       outf->ef_stmax * sizeof(symbol));
  545. -       if  (outf->ef_stvec == NULL)
  546. -               nomem();
  547. -}
  548. -
  549. -/*
  550. - *     Search through existing symbol table for symbol with given
  551. - *     value.  Invent a new one if needed.
  552. - */
  553. -
  554. -symbol getnsymb(fid, seg, pos)
  555. -register  ef_fid  fid;
  556. -unsigned  seg;
  557. -long   pos;
  558. -{
  559. -       register  int   i;
  560. -       register  symbol  res;
  561. -       
  562. -       /***********  MACHINE DEPENDENT  ******************************
  563. -        *      Convert relocation segment type (argument) to symbol type
  564. -        *      (as remembered in symbol table).  Don't ask me why they
  565. -        *      have to be different.....
  566. -        */
  567. -       
  568. -       seg += TEXT - RTEXT;
  569. -       
  570. -       /*
  571. -        *      See if the reference is to an external symbol.
  572. -        *      If so, use that.
  573. -        */
  574. -       
  575. -       for  (i = 0;  i < fid->ef_stcnt;  i++)  {
  576. -               res = fid->ef_stvec[i];
  577. -               if  (res->s_type == seg  &&  res->s_value == pos)
  578. -                       return  res;
  579. -       }
  580. -       
  581. -       /*
  582. -        *      Invent a symbol and use that.
  583. -        */
  584. -       
  585. -       res = inventsymb("RS");
  586. -       if  (fid->ef_stcnt >= fid->ef_stmax)
  587. -               reallst(fid);
  588. -       fid->ef_stvec[fid->ef_stcnt++] = res;
  589. -       res->s_type = seg;
  590. -       res->s_value = pos;
  591. -       if  (seg == TEXT)  {
  592. -               t_entry tent;
  593. -               gette(fid, pos, &tent);
  594. -               tent.t_bdest = 1;
  595. -               tent.t_lab = res;
  596. -               putte(fid, pos, &tent);
  597. -       }
  598. -       else  if  (seg == DATA  ||  seg == BSS)  {
  599. -               d_entry dent;
  600. -               getd(fid, pos, &dent);
  601. -               dent.d_lab = res;
  602. -               putde(fid, pos, &dent);
  603. -       }
  604. -
  605. -       return  res;
  606. -}
  607. -
  608. -/*
  609. - *     Assuming address given is in text segment, find its label, or invent
  610. - *     one.  Also set where refered from.
  611. - */
  612. -
  613. -symbol textlab(loc, refpos)
  614. -long   loc, refpos;
  615. -{
  616. -       t_entry tent;
  617. -
  618. -       gette(&mainfile, loc, &tent);
  619. -       if  (tent.t_type == T_CONT)
  620. -               return  NULL;
  621. -       if  (tent.t_lab == NULL)  {
  622. -               tent.t_lab = inventsymb("TS");
  623. -               tent.t_lab->s_type = TEXT;
  624. -               tent.t_lab->s_value = loc;
  625. -               tent.t_bdest = 1;
  626. -               putte(&mainfile, loc, &tent);
  627. -       }
  628. -       else
  629. -               tent.t_lab->s_used++;
  630. -       if  (tent.t_refhi < refpos)  {
  631. -               tent.t_refhi = refpos;
  632. -               putte(&mainfile, loc, &tent);
  633. -       }
  634. -       if  (tent.t_reflo > refpos)  {
  635. -               tent.t_reflo = refpos;
  636. -               putte(&mainfile, loc, &tent);
  637. -       }
  638. -       return  tent.t_lab;
  639. -}
  640. -
  641. -/*
  642. - *     Note references to data.
  643. - */
  644. -
  645. -void   mkdref(tpos, size)
  646. -long   tpos;
  647. -unsigned  size;
  648. -{
  649. -       t_entry tent;
  650. -       d_entry dent;
  651. -       register  symbol  ds;
  652. -       int     dchng = 0;
  653. -       int     wsize;
  654. -       long    dpos;
  655. -       
  656. -       gette(&mainfile, tpos, &tent);
  657. -       if  (tent.t_relsymb != NULL)
  658. -               return;
  659. -               
  660. -       dpos = gettw(&mainfile, tpos, R_LONG);
  661. -       if  (dpos < mainfile.ef_dbase  ||  dpos > mainfile.ef_end)
  662. -               return;
  663. -       
  664. -       switch  (size)  {
  665. -       default:
  666. -               wsize = D_BYTE;
  667. -               break;
  668. -       case  2:
  669. -               wsize = D_WORD;
  670. -               break;
  671. -       case  4:
  672. -               wsize = D_LONG;
  673. -               break;
  674. -       }
  675. -       
  676. -       getde(&mainfile, dpos, &dent);
  677. -       if  ((ds = dent.d_lab) == NULL)  {
  678. -               if  (dpos >= mainfile.ef_bbase)  
  679. -                       ds = inventsymb("BS");
  680. -                       ds->s_type = BSS;
  681. -               }
  682. -               else  {
  683. -                       ds = inventsymb("DS");
  684. -                       ds->s_type = DATA;
  685. -               }
  686. -               ds->s_value = dpos;
  687. -               dent.d_lab = ds;
  688. -               dchng++;
  689. -       }
  690. -       else
  691. -               ds->s_used++;
  692. -
  693. -       if  (dent.d_type != D_BYTE)  {
  694. -               if  (dent.d_type != wsize)  {
  695. -                       if  (dent.d_type == D_ADDR)  {
  696. -                               if  (wsize != D_LONG)
  697. -                                       unimpl("Addr word usage");
  698. -                       }
  699. -                       else  if  (dent.d_type > wsize)  {
  700. -                               dchng++;
  701. -                               dent.d_type = wsize;
  702. -                               dent.d_lng = size;
  703. -                       }
  704. -               }
  705. -       }
  706. -       else  {
  707. -               dent.d_type = wsize;
  708. -               dent.d_lng = size;
  709. -               dchng++;
  710. -       }
  711. -       if  (dchng)  {
  712. -               putde(&mainfile, dpos, &dent);
  713. -               for  (dchng = 1;  dchng < size; dchng++)
  714. -                       setde(&mainfile, dpos+dchng, D_CONT, 1);
  715. -       }
  716. -               
  717. -       tent.t_relsymb = ds;
  718. -       putte(&mainfile, tpos, &tent);
  719. -}
  720. -
  721. -/*
  722. - *     Add item to common or abs list.
  723. - */
  724. -
  725. -#define        COMINC  10
  726. -
  727. -void   addit(cp, symb)
  728. -register  struct  commit  *cp;
  729. -symbol symb;
  730. -{
  731. -       if  (cp->c_int >= cp->c_max)  {
  732. -               cp->c_max += COMINC;
  733. -               if  (cp->c_symb == NULL)
  734. -                       cp->c_symb = (symbol *) malloc(COMINC*sizeof(symbol));
  735. -               else
  736. -                       cp->c_symb = (symbol *)
  737. -                                       realloc(cp->c_symb,
  738. -                                               cp->c_max * sizeof(symbol));
  739. -               if  (cp->c_symb == NULL)
  740. -                       nomem();
  741. -      }
  742. -       cp->c_symb[cp->c_int++] = symb;
  743. -}
  744. //GO.SYSIN DD alloc.c
  745. echo file.c 1>&2
  746. sed 's/.//' >file.c <<'//GO.SYSIN DD file.c'
  747. -/*
  748. - *     SCCS:   @(#)file.c      1.2     11/2/84 14:17:35
  749. - *     Various operations on files.
  750. - *
  751. - ***********************************************************************
  752. - *     This software is copyright of
  753. - *
  754. - *             John M Collins
  755. - *             47 Cedarwood Drive
  756. - *             St Albans
  757. - *             Herts, AL4 0DN
  758. - *             England                 +44 727 57267
  759. - *
  760. - *     and is released into the public domain on the following conditions:
  761. - *
  762. - *             1.  No free maintenance will be guaranteed.
  763. - *             2.  Nothing may be based on this software without
  764. - *                 acknowledgement, including incorporation of this
  765. - *                 notice.
  766. - *
  767. - *     Notwithstanding the above, the author welcomes correspondence and bug
  768. - *     fixes.
  769. - ***********************************************************************
  770. - */
  771. -
  772. -#include <stdio.h>
  773. -#include <a.out.h>
  774. -#include "unc.h"
  775. -       
  776. -long   lseek();
  777. -void   unimpl();
  778. -
  779. -/*
  780. - *     Validate addr and get text entry corresponding to it from the given
  781. - *     file.
  782. - */
  783. -
  784. -void   gette(fid, addr, te)
  785. -register  ef_fid  fid;
  786. -register  long addr;
  787. -t_entry        *te;
  788. -{
  789. -       addr -= fid->ef_tbase;
  790. -       if  (addr < 0  ||  addr > fid->ef_tsize  || (addr & 1) != 0)  {
  791. -               (void) fprintf(stderr, "Invalid text address %lx\n", addr);
  792. -               exit(200);
  793. -       }
  794. -       (void) lseek(fid->ef_t, (long)(addr * sizeof(t_entry)/2), 0);
  795. -       if  (read(fid->ef_t, (char *) te, sizeof(t_entry)) != sizeof(t_entry))  {
  796. -               (void) fprintf(stderr, "Trouble reading text at %lx\n", addr);
  797. -               exit(201);
  798. -       }
  799. -}
  800. -
  801. -/*
  802. - *     Store a text entry.
  803. - */
  804. -
  805. -void   putte(fid, addr, te)
  806. -register  ef_fid  fid;
  807. -register  long addr;
  808. -t_entry        *te;
  809. -{
  810. -       addr -= fid->ef_tbase;
  811. -      if  (addr < 0  ||  addr > fid->ef_tsize  ||  (addr & 1) != 0)  {
  812. -               (void) fprintf(stderr, "Invalid text address %lx\n", addr);
  813. -               exit(200);
  814. -       }
  815. -       (void) lseek(fid->ef_t, (long)(addr * sizeof(t_entry)/2), 0);
  816. -       (void) write(fid->ef_t, (char *) te, sizeof(t_entry));
  817. -}
  818. -
  819. -/*
  820. - *     Validate addr and get data entry corresponding to it from the given
  821. - *     file.
  822. - */
  823. -
  824. -void   getde(fid, addr, de)
  825. -register  ef_fid  fid;
  826. -register  long addr;
  827. -d_entry        *de;
  828. -{
  829. -       if  (addr < fid->ef_dbase  ||  addr > fid->ef_end)  {
  830. -               (void) fprintf(stderr, "Invalid data address %lx\n", addr);
  831. -               exit(200);
  832. -       }
  833. -       addr -= fid->ef_dbase;
  834. -       (void) lseek(fid->ef_d, (long)(addr * sizeof(d_entry)), 0);
  835. -       if  (read(fid->ef_d, (char *) de, sizeof(d_entry)) != sizeof(d_entry))  {
  836. -               (void) fprintf(stderr, "Trouble reading data at %lx\n", addr);
  837. -               exit(201);
  838. -       }
  839. -}
  840. -
  841. -/*
  842. - *     Store a data entry.
  843. - */
  844. -
  845. -void   putde(fid, addr, de)
  846. -register  ef_fid  fid;
  847. -register  long addr;
  848. -d_entry        *de;
  849. -{
  850. -       if  (addr < fid->ef_dbase  ||  addr > fid->ef_end)  {
  851. -               (void) fprintf(stderr, "Invalid data address %lx\n", addr);
  852. -               exit(200);
  853. -       }
  854. -       addr -= fid->ef_dbase;
  855. -       (void) lseek(fid->ef_d, (long)(addr * sizeof(d_entry)), 0);
  856. -       (void) write(fid->ef_d, (char *) de, sizeof(d_entry));
  857. -}
  858. -
  859. -/*
  860. - *     Set type and length of given data entry.
  861. - */
  862. -
  863. -void   setde(fid, addr, type, lng)
  864. -ef_fid fid;
  865. -long   addr;
  866. -unsigned  type;
  867. -int    lng;
  868. -{
  869. -       d_entry dat;
  870. -
  871. -       if  (addr > fid->ef_end)
  872. -               return;
  873. -       getde(fid, addr, &dat);
  874. -       if  (type == D_CONT  &&  dat.d_reloc != R_NONE)  {
  875. -               char    obuf[30];
  876. -               (void) sprintf(obuf, "overlapped reloc 0x%x", addr);
  877. -               unimpl(obuf);
  878. -       }
  879. -       dat.d_type = type;
  880. -       at.d_lng = lng;
  881. -       putde(fid, addr, &dat);
  882. -}
  883. -       
  884. -/*
  885. - *     Get a word of data file, size as requested.
  886. - */
  887. -
  888. -long   getdw(fid, pos, size)
  889. -register  ef_fid  fid;
  890. -long   pos;
  891. -int    size;
  892. -{
  893. -       d_entry dat;
  894. -       register  long  res;
  895. -       register  int   i, lt;
  896. -       
  897. -       getde(fid, pos, &dat);
  898. -       
  899. -       switch  (size)  {
  900. -       case  R_BYTE:
  901. -               return  dat.d_contents;
  902. -               
  903. -       case  R_LONG:
  904. -               lt = 4;
  905. -               goto  rest;
  906. -               
  907. -       case  R_WORD:
  908. -               lt = 2;
  909. -       rest:
  910. -               res = dat.d_contents;
  911. -               for  (i = 1;  i < lt; i++)  {
  912. -                       getde(fid, pos+i, &dat);
  913. -                       res = (res << 8) + dat.d_contents;
  914. -               }
  915. -               return  res;
  916. -               
  917. -       default:
  918. -               (void) fprintf(stderr, "Data word size error\n");
  919. -               exit(20);
  920. -       }
  921. -       /*NOTREACHED*/
  922. -}
  923. -
  924. -/*
  925. - *     Get a word of text file.
  926. - */
  927. -
  928. -long   gettw(fid, pos, size)
  929. -register  ef_fid  fid;
  930. -long   pos;
  931. -int    size;
  932. -{
  933. -       t_entry tex;
  934. -       long    res;
  935. -       
  936. -       gette(fid, pos, &tex);
  937. -       
  938. -       switch  (size)  {
  939. -       case  R_BYTE:
  940. -               return  tex.t_contents >> 8;
  941. -               
  942. -       case  R_WORD:
  943. -               return  tex.t_contents;
  944. -               
  945. -       case  R_LONG:
  946. -               res = tex.t_contents;
  947. -               gette(fid, pos+2, &tex);
  948. -               return  (res << 16) + tex.t_contents;
  949. -       default:
  950. -               (void) fprintf(stderr, "Text word size error\n");
  951. -               exit(20);
  952. -       }
  953. -       /*NOTREACHED*/
  954. -}
  955. //GO.SYSIN DD file.c
  956. echo heur.c 1>&2
  957. sed 's/.//' >heur.c <<'//GO.SYSIN DD heur.c'
  958. -/*
  959. - *     SCCS:   @(#)heur.c      1.2     11/2/84 14:17:46
  960. - *     Attempt to guess things about the file.
  961. - *
  962. - **********************************************************************
  963. - *     This software is copyright of
  964. - *
  965. - *             John M Collins
  966. - *             47 Cedarwood Drive
  967. - *             St Albans
  968. - *             Herts, AL4 0DN
  969. - *             England                 +44 727 57267
  970. - *
  971. - *     and is released into the public domain on the following conditions:
  972. - *
  973. - *             1.  No free maintenance will be guaranteed.
  974. - *             2.  Nothing may be based on this software without
  975. - *                 acknowledgement, including incorporation of this
  976. - *                 notice.
  977. - *
  978. - *     Notwithstanding the above, the author welcomes correspondence and bug
  979. - *     fixes.
  980. - ***********************************************************************
  981. - */
  982. -
  983. -#include <stdio.h>
  984. -#include <a.out.h>
  985. -#include "unc.h"
  986. -
  987. -#define        INITDAT 256
  988. -#define        INCDAT  128
  989. -
  990. -#define        STRSCNT 3
  991. -#define        STRECNT 3
  992. -
  993. -char   *malloc(), *realloc();
  994. -
  995. -void   gette(), getde(), setde(), putte(), putde();
  996. -void   nomem();
  997. -long   getdw();
  998. -symbol inventsymb();
  999. -
  1000. -long   endt;
  1001. -ef_fids        mainfile;
  1002. -
  1003. -/*
  1004. - *     Talk about implemented things.....
  1005. - */
  1006. -
  1007. -void   unimpl(msg)
  1008. -char   *msg;
  1009. -{
  1010. -       (void) fprintf(stderr, "Warning: handling of \"%s\" not implemented\n", msg);
  1011. -}
  1012. -
  1013. -/*
  1014. - *     Return 1 if string char, otherwise 0.
  1015. - */
  1016. -
  1017. -int    possstr(x)
  1018. -unsigned  x;
  1019. -{
  1020. -       if  (x >= ' '  &&  x <= '~')
  1021. -               return  1;
  1022. -       if  (x == '\n'  ||  x == '\t')
  1023. -               return  1;
  1024. -       return  0;
  1025. -}
  1026. -
  1027. -/*
  1028. - *     Guess things about data files.
  1029. - */
  1030. -
  1031. -void   intudat(fid)
  1032. -ef_fid  fid;
  1033. -{
  1034. -       register  int   i, j;
  1035. -       int     lt, input, invcnt;
  1036. -       long    offs, soffs, endd;
  1037. -       d_entry fdat;
  1038. -       unsigned  char  *inbuf;
  1039. -       int     ibsize;
  1040. -       
  1041. -       inbuf = (unsigned  char *)malloc(INITDAT);
  1042. -       if  (inbuf == NULL)
  1043. -               nomem();
  1044. -       ibsize = INITDAT;
  1045. -       
  1046. -       offs = fid->ef_dbase;
  1047. -       endd = fid->e_bbase;
  1048. -
  1049. -       while  (offs < endd)  {
  1050. -               getde(fid, offs, &fdat);
  1051. -               if  (fdat.d_type != D_BYTE)  {
  1052. -                       offs += fdat.d_lng;
  1053. -                       continue;
  1054. -               }
  1055. -               
  1056. -               /*
  1057. -                *      Looks like general data.  Read in as much as possible.
  1058. -                */
  1059. -               
  1060. -               input = 0;
  1061. -               soffs = offs;
  1062. -               do  {
  1063. -                       if  (input >= ibsize)  {
  1064. -                               ibsize += INCDAT;
  1065. -                               inbuf = (unsigned  char *)
  1066. -                                       realloc((char *)inbuf, (unsigned)ibsize);
  1067. -                               if  (inbuf == NULL)
  1068. -                                       nomem();
  1069. -                       }
  1070. -                       inbuf[input++] = fdat.d_contents;
  1071. -                       offs++;
  1072. -                       if  (offs >= endd)
  1073. -                               break;
  1074. -                       getde(fid, offs, &fdat);
  1075. -               }  while  (fdat.d_type == D_BYTE && fdat.d_lab == NULL);
  1076. -               
  1077. -               /*
  1078. -                *      Now split up the data.
  1079. -                */
  1080. -               
  1081. -               for  (i = 0;  i < input;  )  {
  1082. -                       
  1083. -                       /*
  1084. -                        *      Might be a string.
  1085. -                        */
  1086. -                       
  1087. -                       if  (possstr(inbuf[i]))  {
  1088. -                               lt = input;
  1089. -                               if  (i + STRSCNT < lt)
  1090. -                                       lt = i + STRSCNT;
  1091. -                               for  (j = i + 1;  j < lt;  j++)  {
  1092. -                                       if  (inbuf[j] == '\0')
  1093. -                                               break;
  1094. -                                       if  (!possstr(inbuf[j]))
  1095. -                                               goto  notstr;
  1096. -                               }
  1097. -                              
  1098. -                               /*
  1099. -                                *      Looks like a string then.
  1100. -                                */
  1101. -                               
  1102. -                               invcnt = 0;
  1103. -                               for  (j = i + 1; j < input;  j++)  {
  1104. -                                       if  (inbuf[j] == '\0')  {
  1105. -                                               j++;
  1106. -                                               break;
  1107. -                                       }
  1108. -                                       if  (possstr(inbuf[j]))
  1109. -                                               invcnt = 0;
  1110. -                                       else  {
  1111. -                                               invcnt++;
  1112. -                                               if  (invcnt >= STRECNT)  {
  1113. -                                                       j -= invcnt - 1;
  1114. -                                                       break;
  1115. -                                               }
  1116. -                                       }
  1117. -                               }
  1118. -
  1119. -                               setde(fid,
  1120. -                                     soffs+i,
  1121. -                                     (unsigned)(inbuf[j-1]=='\0'?D_ASCZ:D_ASC),-                                     j - i);
  1122. -                               for  (i++;  i < j;  i++)
  1123. -                                       setde(fid, soffs+i, D_CONT, 1); 
  1124. -                               continue;
  1125. -                       }
  1126. -
  1127. -notstr:
  1128. -                       /*
  1129. -                        *      If on odd boundary, treat as a byte.
  1130. -                        */
  1131. -                       
  1132. -                       if  ((soffs + i) & 1  ||  i + 1 >= input)  {
  1133. -                               setde(fid, soffs + i, D_BYTE, 1);
  1134. -                               i++;
  1135. -                               continue;
  1136. -                       }
  1137. -
  1138. -                       /*
  1139. -                        *      Treat as longs unless not enough.
  1140. -                        */
  1141. -                       
  1142. -                       if  (i + 3 >= input)  {
  1143. -                               setde(fid, soffs + i, D_WORD, 2);
  1144. -                               setde(fid, soffs + i + 1, D_CONT, -1);
  1145. -                               i += 2;
  1146. -                               continue;
  1147. -                       }
  1148. -
  1149. -                       /*
  1150. -                        *      Treat as a long but mark changable.
  1151. -                        */
  1152. -                       
  1153. -                       setde(fid, soffs + i, D_LONG, 4);
  1154. -                       for  (j = 1;  j < 4;  j++)
  1155. -                               setde(fid, soffs + i + j, D_CONT, -j);
  1156. -                       i += 4;
  1157. -               }
  1158. -       }
  1159. -       free((char *)inbuf);
  1160. -       
  1161. -       /*
  1162. -        *      Now zap bss segment.
  1163. -        */
  1164. -       
  1165. -       offs = fid->ef_bbase;
  1166. -       endd = fid->ef_end;
  1167. -
  1168. -       while  (offs < endd)  {
  1169. -               getde(fid, offs, &fdat);
  1170. -               if  (fdat.d_type != D_BYTE)  {
  1171. -                       offs += fdat.d_lng;
  1172. -                       continue;
  1173. -               }
  1174. -
  1175. -               soffs = offs;
  1176. -               do  {
  1177. -                       offs++;
  1178. -                       if  (offs >= endd)
  1179. -                               break;
  1180. -                       getde(fid, offs, &fdat);
  1181. -               }  while  (fdat.d_type == D_BYTE && fdat.d_lab == NULL);
  1182. -               
  1183. -               setde(fid, soffs, D_BYTE, (int)(offs-soffs));
  1184. -               for  (i = -1, soffs++;  soffs < offs; i--, soffs++)
  1185. -                       setde(fid, soffs, D_CONT, i); 
  1186. -       }
  1187. -}
  1188. -
  1189. -/*
  1190. - *     For non relocatable files, try to identify address pointers in
  1191. - *     the data.
  1192. - */
  1193. -
  1194. -void   inturdat(fid)
  1195. -ef_fid fid;
  1196. -{
  1197. -       register  long  offs = fid->ef_dbase;
  1198. -       register  int   i;
  1199. -       register  symbol  ds;
  1200. -       long  endd = fid->ef_bbase;
  1201. -       long  cont;
  1202. -       d_entry dent, refdent;
  1203. -
  1204. -       while  (offs < endd) {
  1205. -               getde(fid, offs, &dent);
  1206. -               if  (dent.d_type != D_LONG)
  1207. -                       goto  endit;
  1208. -               cont = getdw(fid, offs, R_LONG);
  1209. -               if  (cont < fid->ef_dbase || cont > fid->ef_end)
  1210. -                       goto  endit;
  1211. -               getde(fid, cont, &refdent);
  1212. -               if  (refdent.d_type == D_CONT)  {
  1213. -                       d_entry pdent;
  1214. -                       int     siz;
  1215. -                       
  1216. -                       if  (refdent.d_lng >= 0)
  1217. -                               goto  endit;
  1218. -                       getde(fid, cont+refdent.d_lng, &pdent);
  1219. -                       i = -refdent.d_lng;
  1220. -                       refdent.d_lng += pdent.d_lng;
  1221. -                       pdent.d_lng = i;
  1222. -                       if  (pdent.d_type == D_LONG  &&  i == 2)
  1223. -                               siz = D_WORD;
  1224. -                       else
  1225. -                               siz = D_BYTE;
  1226. -                       refdent.d_type = siz;
  1227. -                       pdent.d_type = siz;
  1228. -                       putde(fid, cont - i, &pdent);
  1229. -                       for  (i = 1;  i < refdent.d_lng;  i++)
  1230. -                               setde(fid, cont+i, D_CONT, -i);
  1231. -               }
  1232. -               if  ((ds = refdent.d_lab) == NULL)  {
  1233. -                       if  (cont >= fid->ef_bbase)  {
  1234. -                               ds = inventsymb("BS");
  1235. -                               ds->s_type = BSS;
  1236. -                       }
  1237. -                       else  {
  1238. -                               ds = inventsymb("DS");
  1239. -                               ds->s_type = DATA;
  1240. -                       }
  1241. -                       ds->s_value = cont;
  1242. -                       refdent.d_lab = ds;
  1243. -                       putde(fid, cont, &refdent);
  1244. -               }
  1245. -               else
  1246. -                       ds->s_used++;
  1247. -               dent.d_type = D_ADDR;
  1248. -               dent.d_relsymb = ds;
  1249. -               dent.d_rptr = ds->s_type;
  1250. -               putdefid, offs, &dent);
  1251. -               for  (i = 1;  i < 4;  i++)
  1252. -                       setde(fid, offs+i, D_CONT, 1);
  1253. -endit:
  1254. -               offs += dent.d_lng;
  1255. -       }
  1256. -}
  1257. -
  1258. -/*
  1259. - *     Recursively follow through the code, stopping at unconditional
  1260. - *     branches and invalid instructions.
  1261. - */
  1262. -
  1263. -void   follseq(pos)
  1264. -long   pos;
  1265. -{
  1266. -       t_entry tent;
  1267. -       int     lng;
  1268. -       long    npos;
  1269. -
  1270. -       while  (pos < endt)  {
  1271. -               gette(&mainfile, pos, &tent);
  1272. -               if  (tent.t_amap)       /*  Been here  */
  1273. -                       return;
  1274. -               tent.t_amap = 1;
  1275. -               lng = findinst(&tent, pos);
  1276. -               npos = pos + lng*2;
  1277. -               if  (npos > endt)  {
  1278. -                       tent.t_vins = 0;
  1279. -                       tent.t_lng = 1;
  1280. -                       tent.t_type = T_UNKNOWN;
  1281. -                       lng = 0;
  1282. -                       npos = endt;
  1283. -               }
  1284. -               putte(&mainfile, pos, &tent);
  1285. -               pos = npos;
  1286. -               
  1287. -               if  (lng <= 0)
  1288. -                       return;
  1289. -
  1290. -               switch  (tent.t_bchtyp)  {
  1291. -               case  T_UNBR:
  1292. -                       if  (tent.t_relsymb == NULL)
  1293. -                               return;
  1294. -                       pos = tent.t_relsymb->s_value;
  1295. -                       continue;
  1296. -               case  T_JSR:
  1297. -                       if  (tent.t_relsymb != NULL)
  1298. -                               follseq(tent.t_relsymb->s_value);
  1299. -                       continue;
  1300. -               case  T_CONDBR:
  1301. -                       follseq(tent.t_relsymb->s_value);
  1302. -               default:
  1303. -                       continue;
  1304. -               }
  1305. -       }
  1306. -}
  1307. -                       
  1308. -                       
  1309. -/*
  1310. - *     Try to work out things about text files.
  1311. - */
  1312. -
  1313. -void   intutext()
  1314. -{
  1315. -       long    pos;
  1316. -       t_entry tent;
  1317. -       int     lng;
  1318. -       
  1319. -       endt = mainfile.ef_tbase + mainfile.ef_tsize;
  1320. -      pos = mainfile.ef_entry;
  1321. -nextv:
  1322. -       for  (;  pos < endt;)  {
  1323. -               gette(&mainfile, pos, &tent);
  1324. -               if  (!tent.t_amap && tent.t_vins)  {
  1325. -                       follseq(pos);
  1326. -                       pos += 2;
  1327. -                       goto  nextiv;
  1328. -               }
  1329. -               pos += tent.t_lng * 2;
  1330. -               if  (tent.t_bchtyp == T_UNBR)
  1331. -                       goto  nextiv;
  1332. -       }
  1333. -       goto    dorest;
  1334. -nextiv:
  1335. -       for  (;  pos < endt;  pos += 2)  {
  1336. -               gette(&mainfile, pos, &tent);
  1337. -               if  (tent.t_bdest)
  1338. -                       goto  nextv;
  1339. -       }
  1340. -dorest:
  1341. -       /*
  1342. -        *      Deal with unmapped instructions.
  1343. -        */
  1344. -       
  1345. -       for  (pos = 0;  pos < endt;)  {
  1346. -               gette(&mainfile, pos, &tent);
  1347. -               switch  (tent.t_type)  {
  1348. -               case  T_BEGIN:
  1349. -                       pos += tent.t_lng * 2;
  1350. -                       continue;
  1351. -               case  T_UNKNOWN:
  1352. -                       if  (tent.t_vins)  {
  1353. -                               lng = findinst(&tent, pos);
  1354. -                               putte(&mainfile, pos, &tent);
  1355. -                               if  (lng > 0)  {
  1356. -                                       pos += lng * 2;
  1357. -                                       continue;
  1358. -                               }
  1359. -                       }
  1360. -               default:
  1361. -                       pos += 2;
  1362. -                       continue;
  1363. -               }
  1364. -       }
  1365. -}
  1366. -
  1367. -/*
  1368. - *     Invent local symbols.
  1369. - */
  1370. -
  1371. -void   intlsym()
  1372. -{
  1373. -       long    bpos, epos, hiref, hipos;
  1374. -       unsigned  llnum;
  1375. -       t_entry tent;
  1376. -       register  symbol  tl;
  1377. -       
  1378. -       endt = mainfile.ef_tbase + mainfile.ef_tsize;
  1379. -       epos = mainfile.ef_entry;
  1380. -       for  (;;)  {
  1381. -               bpos = epos;
  1382. -               hiref = bpos;
  1383. -               if  (epos >= endt)
  1384. -                       return;
  1385. -               gette(&mainfile, epos, &tent);
  1386. -              epos += tent.t_lng * 2;
  1387. -               for  (;  epos < endt;)  {
  1388. -                       gette(&mainfile, epos, &tent);
  1389. -                       if  (tent.t_gbdest  ||  tent.t_dref)
  1390. -                               break;
  1391. -                       if  (tent.t_reflo < bpos)
  1392. -                               break;
  1393. -                       if  (tent.t_refhi > hiref)  {
  1394. -                               hiref = tent.t_refhi;
  1395. -                               hipos = epos;
  1396. -                       }
  1397. -                       epos += tent.t_lng * 2;
  1398. -               }
  1399. -               if  (hiref > epos)
  1400. -                       epos = hipos;
  1401. -               llnum = 0;
  1402. -               for  (hipos = bpos;  hipos < epos;)  {
  1403. -                       gette(&mainfile, hipos, &tent);
  1404. -                       if  (!tent.t_gbdest && !tent.t_dref &&
  1405. -                        tent.t_reflo >= bpos && tent.t_refhi < epos &&
  1406. -                        (tl = tent.t_lab) != NULL)
  1407. -                               tl->s_lsymb = ++llnum;
  1408. -                       hipos += tent.t_lng * 2;
  1409. -               }
  1410. -       }
  1411. -}
  1412. -
  1413. -/*
  1414. - *     Given the main file, a possible candidate for matching in the
  1415. - *     file and an offset, see if text matches.  Return 1 if matches,
  1416. - *     or 0 if no match.
  1417. - */
  1418. -
  1419. -int    matchup(mf, lf, startpos)
  1420. -register  ef_fid  mf, lf;
  1421. -long   startpos;
  1422. -{
  1423. -       register  int   i, matches = 0;
  1424. -       t_entry ltent, mtent;
  1425. -
  1426. -       if  (lf->ef_tsize > mf->ef_tsize - startpos + mf->ef_tbase)
  1427. -               return  0;      /*  At end - can't fit  */
  1428. -
  1429. -       for  (i = 0;  i < lf->ef_tsize;  i += 2)  {
  1430. -               gette(lf, lf->ef_tbase + i, <ent);
  1431. -               if  (ltent.t_isrel)
  1432. -                       continue;
  1433. -               gette(mf, startpos + i, &mtent);
  1434. -               if  (mtent.t_contents != ltent.t_contents)
  1435. -                       return  0;
  1436. -               matches++;
  1437. -       }
  1438. -       
  1439. -       /*
  1440. -        *      Give up on zero length or all relocatable fils.
  1441. -        */
  1442. -       
  1443. -       return  matches > 0;
  1444. -}
  1445. -
  1446. -/*
  1447. - *     Scan through main file looking for a match.
  1448. - */
  1449. -
  1450. -long   findstart(mf, lf)
  1451. -register  ef_fid  mf, lf;
  1452. -{
  1453. -       register  long  res = mf->ef_tbase;
  1454. -       long    lim = mf->ef_tbase + mf->ef_tsize - lf->ef_tsize;
  1455. -       t_entry tent;
  1456. -       
  1457. -restart:
  1458. -       for  (;  res <= lim;  res += 2)  {
  1459. -               gette(mf, res, &tent);
  1460. -               if  (tent.t_match != 0)  {
  1461. -                       res += tent.t_match;
  1462. -                       goto  restart;
  1463. -               }
  1464. -               if  (matchup(mf, lf, res))
  1465. -                       return  res;
  1466. -       }
  1467. -       return  -1;
  1468. -}
  1469. -
  1470. -/*
  1471. - *     Mark the head of a matched module to save searching.
  1472. - */
  1473. -
  1474. -void   markmatch(mf, lf, pos)
  1475. -ef_fid mf, lf;
  1476. -long   pos;
  1477. -{
  1478. -       t_entry tent;
  1479. -       
  1480. -       gette(mf, pos, &tent);
  1481. -       tent.t_match = (unsigned) lf->ef_tsize;
  1482. -       putte(mf, pos, &tent);
  1483. -}
  1484. //GO.SYSIN DD heur.c
  1485. echo iset.c 1>&2
  1486. sed 's/.//' >iset.c <<'//GO.SYSIN DD iset.c'
  1487. -/*
  1488. - *     SCCS:   @(#)iset.c      1.2     11/2/84 14:18:23
  1489. - *     Decode instructions.
  1490. - *
  1491. - ***********************************************************************
  1492. - *     This software is copyright of
  1493. - *
  1494. - *             John M Collins
  1495. - *             47 Cedarwood Drive
  1496. - *             St Albans
  1497. - *             Herts, AL4 0DN
  1498. - *             England                 +44 727 57267
  1499. - *
  1500. - *     and is released into the public domain on the following conditions:
  1501. - *
  1502. - *             1.  No free maintenance will be guaranteed.
  1503. - *             2.  Nothing may be based on this software without
  1504. - *                 acknowledgement, including incorporation of this
  1505. - *                 notice.
  1506. - *
  1507. - *     Notwithstanding the above, the author welcomes correspondence and bug
  1508. - *     fixes.
  1509. - ***********************************************************************
  1510. - */
  1511. -
  1512. -#include <stdio.h>
  1513. -#include <a.out.h>
  1514. -#include "unc.h"
  1515. -
  1516. -ef_fids       mainfile;
  1517. -long   endt;
  1518. -
  1519. -void   gette(), putte();
  1520. -void   mkdref();
  1521. -long   gettw();
  1522. -symbol textlab();
  1523. -
  1524. -int    l1(), l2(), el1(), lea(), lmove(), lcbch(), jj();
  1525. -int    limed(), lsbit(), lmvml(), lone(), loone(), lonew(), lonel();
  1526. -
  1527. -int    pmove(), pcbch(), pdbcc(), pscc(), pcs(), pmovc(), pstop(), pexg();
  1528. -int    pimed(), pmovp(), psbit(), pdbit(), pcs2(), pone(), ppea();
  1529. -int    plea(), pdreg(), pmvml(), ptrap(), plink(), pareg(), podreg();
  1530. -int    pqu(), pmqu(), ptreg(), pcmpm(), pomode(), pmshf(), pshf();
  1531. -
  1532. -struct opstr   {
  1533. -       unsigned  short  mask;
  1534. -       unsigned  short  match;
  1535. -       int     (*opsize)();
  1536. -       int     (*opprin)();
  1537. -       char    *prarg;
  1538. -} optab[] = {
  1539. -       0xf000, 0x2000, lmove, pmove, "l",
  1540. -       0xf000, 0x3000, lmove, pmove, "w",
  1541. -       0xf000, 0x1000, lmove, pmove, "b",
  1542. -       0xf000, 0x6000, lcbch, pcbch, 0,
  1543. -       0xffbf, 0x003c, l2,    pcs,   "or",
  1544. -       0xff00, 0x0000, limed, pimed, "or",
  1545. -       0xffbf, 0x023c, l2,    pcs,   "and",
  1546. -       0xff00, 0x0200, limed, pimed, "and",
  1547. -       0xff00, 0x0400, limed, pimed, "sub",
  1548. -       0xff00, 0x0600, limed, pimed, "add",
  1549. -       0xffbf, 0x0a3c, l2,    pcs,   "eor",
  1550. -       0xff00, 0x0a00, limed, pimed, "eor",
  1551. -       0xff00, 0x0c00, limed, pimed, "cmp",
  1552. -       0xf138, 0x0108, l2,    pmovp, 0,
  1553. -       0xff00, 0x0800, lsbit, psbit, 0,
  1554. -       0xf100, 0x0100, lonew, pdbit, 0,
  1555. -       0xffc0, 0x40c0, lonew, pcs2,  "sr",
  1556. -       0xff00, 0x4000, lone,  pone,  "negx",
  1557. -       0xff00, 0x4200, lone,  pone,  "clr",
  1558. -       0xffc0, 0x44c0, lonew, pcs2,  "cc",
  1559. -       0xff00, 0x4400, lone,  pone,  "neg",
  1560. -       0xffc0, 0x46c0, lonew, pcs2,  "sr",
  1561. -       0xff00, 0x4600, lone,  pone,  "not",
  1562. -       0xffc0, 0x4800, lonew, ppea,  "nbcd",
  1563. -       0xfff8, 0x4840, l1,    pdreg, "swap",
  1564. -       0xffc0, 0x4840, lonel, ppea,  "pea",
  1565. -       0xfff8, 0x4880, l1,    pdreg, "extw",
  1566. -       0xfff8, 0x48c0, l1,    pdreg, "extl",
  1567. -       0xfb80, 0x4880, lmvml, pmvml, 0,
  1568. -       0ffc0, 0x4ac0, lonew, ppea,  "tas",
  1569. -       0xff00, 0x4a00, lone,  pone,  "tst",
  1570. -       0xfff0, 0x4e40, l1,    ptrap, 0,
  1571. -       0xfff8, 0x4e50, l2,    plink, 0,
  1572. -       0xfff8, 0x4e58, l1,    pareg, "unlk\t%s",
  1573. -       0xfff8, 0x4e60, l1,    pareg, "movl\t%s,usp",
  1574. -       0xfff8, 0x4e68, l1,    pareg, "movl\tusp,%s",
  1575. -       0xffff, 0x4e70, l1,    pareg, "reset",
  1576. -       0xffff, 0x4e71, l1,    pareg, "nop",
  1577. -       0xffff, 0x4e72, l2,    pstop, 0,
  1578. -       0xffff, 0x4e73, el1,   pareg, "rte",
  1579. -       0xffff, 0x4e75, el1,   pareg, "rts",
  1580. -       0xffff, 0x4e76, l1,    pareg, "trapv",
  1581. -       0xffff, 0x4e77, el1,   pareg, "rtr",
  1582. -       0xfffe, 0x4e7a, l2,    pmovc, 0,
  1583. -       0xffc0, 0x4e80, jj,    ppea,  "jsr",
  1584. -       0xffc0, 0x4ec0, jj,    ppea,  "jmp",
  1585. -       0xf1c0, 0x4180, lonew, podreg,"chk",
  1586. -       0xf1c0, 0x41c0, lonel, plea,  0,
  1587. -       0xf0f8, 0x50c8, lcbch, pdbcc, 0,
  1588. -       0xf0c0, 0x50c0, lonew, pscc,  0,
  1589. -       0xf100, 0x5000, lone,  pqu,   "add",
  1590. -       0xf100, 0x5100, lone,  pqu,   "sub",
  1591. -       0xf100, 0x7000, l1,    pmqu,  0,
  1592. -       0xf1c0, 0x80c0, lonew, podreg,"divu",
  1593. -       0xf1c0, 0x81c0, lonew, podreg,"divs",
  1594. -       0xf1f0, 0x8100, l1,    ptreg, "sbcd",
  1595. -       0xf000, 0x8000, loone, pomode,"or",
  1596. -       0xf1f0, 0x9100, l1,    ptreg, "subxb",
  1597. -       0xf1f0, 0x9140, l1,    ptreg, "subxw",
  1598. -       0xf1f0, 0x9180, l1,    ptreg, "subxl",
  1599. -       0xf000, 0x9000, loone, pomode,"sub",
  1600. -       0xf1f8, 0xb108, l1,    pcmpm, "cmpmb",
  1601. -       0xf1f8, 0xb148, l1,    pcmpm, "cmpmw",
  1602. -       0xf1f8, 0xb188, l1,    pcmpm, "cmpml",
  1603. -       0xf100, 0xb000, loone, pomode,"cmp",
  1604. -       0xf1c0, 0xb1c0, loone, pomode,"cmp",
  1605. -       0xf100, 0xb100, loone, pomode,"eor",
  1606. -       0xf1c0, 0xc0c0, lonew, podreg,"mulu",
  1607. -       0xf1c0, 0xc1c0, lonew, podreg,"muls",
  1608. -       0xf1f0, 0xc100, l1,    ptreg, "abcd",
  1609. -       0xf130, 0xc100, l1,    pexg,  0,
  1610. -       0xf000, 0xc000, loone, pomode,"and",
  1611. -       0xf1f0, 0xd100, l1,    ptreg, "addxb",
  1612. -       0xf1f0, 0xd140, 1,    ptreg, "addxw",
  1613. -       0xf1f0, 0xd180, l1,    ptreg, "addxl",
  1614. -       0xf000, 0xd000, loone, pomode,"add",
  1615. -       0xf8c0, 0xe0c0, lonew, pmshf,  0,
  1616. -       0xf000, 0xe000, l1,    pshf,   0,
  1617. -       0
  1618. -};
  1619. -
  1620. -char   *areg[] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp"};
  1621. -char   *cclist[] = { "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs",
  1622. -                       "pl", "mi", "ge", "lt", "gt", "le"};
  1623. -       
  1624. -char   *shtype[] = { "as", "ls", "rox", "ro" };
  1625. -char   *bittyp[] = { "tst", "chg", "clr", "set" };
  1626. -
  1627. -char   *creg[] = { "sfc", "dfc", "usp", "vbr" };
  1628. -
  1629. -/*
  1630. - *     Length functions.
  1631. - */
  1632. -
  1633. -int    l1()
  1634. -{
  1635. -       return  1;
  1636. -}
  1637. -
  1638. -int    l2()
  1639. -{
  1640. -       return  2;
  1641. -}
  1642. -
  1643. -int    el1(te)
  1644. -t_entry        *te;
  1645. -{
  1646. -       te->t_bchtyp = T_UNBR;
  1647. -       return  1;
  1648. -}
  1649. -
  1650. -int    lea(instr, size, pos)
  1651. -unsigned  instr, size;
  1652. -long   pos;
  1653. -{
  1654. -       switch  ((instr >> 3) & 0x7)  {
  1655. -       case  0:
  1656. -       case  1:
  1657. -       case  2:
  1658. -       case  3:
  1659. -       case  4:
  1660. -               return  1;
  1661. -       case  5:
  1662. -       case  6:
  1663. -               return  2;
  1664. -       default:
  1665. -               switch  (instr & 0x7)  {
  1666. -               case  0:
  1667. -               case  2:
  1668. -               case  3:
  1669. -                       return  2;
  1670. -               case  1:
  1671. -                       mkdref(pos, size);
  1672. -                       return  3;
  1673. -               case  4:
  1674. -                       if  (size > 2)
  1675. -                               return  3;
  1676. -                       return  2;
  1677. -               default:
  1678. -                       return  0;
  1679. -               }
  1680. -       }
  1681. -}
  1682. -
  1683. -/*
  1684. - *     Lengths of move instructions.
  1685. - */
  1686. -
  1687. -int    lmove(te, pos)
  1688. -t_entry        *te;
  1689. -long   pos;
  1690. -{
  1691. -       register  unsigned  tc  =  te->t_contents;
  1692. -       unsigned  sz  =  1;
  1693. -       int     lng, lng2;
  1694. -       
  1695. -       lng  = tc & 0xf000;
  1696. -       if  (lng == 0x3000)
  1697. -               sz = 2;
  1698. -       else  if  (lng == 0x2000)
  1699. -               sz = 4;
  1700. -       
  1701. -       i  ((lng = lea(tc, sz, pos+2)) <= 0)
  1702. -               return  0;
  1703. -       lng2 = lea(((tc>>3) & 0x38) | ((tc>>9) & 0x7), sz, pos+lng+lng);
  1704. -       if  (lng2 <= 0)
  1705. -               return  0;
  1706. -       return  lng + lng2 - 1;
  1707. -}
  1708. -
  1709. -/*
  1710. - *     Lengths for conditional branches and dbcc instructions.
  1711. - */
  1712. -
  1713. -int    lcbch(te, pos)
  1714. -t_entry        *te;
  1715. -long   pos;
  1716. -{
  1717. -       unsigned  tc  =  te->t_contents;
  1718. -       long    dest  =  pos + 2;
  1719. -       int     res   =  2;
  1720. -       
  1721. -       if  ((tc & 0xf000) == 0x5000  ||  (tc & 0xff) == 0)
  1722. -               dest += (short)gettw(&mainfile, pos+2, R_WORD);
  1723. -       else  {
  1724. -               dest += (char) tc;
  1725. -               res = 1;
  1726. -       }
  1727. -       if  ((tc & 0xff00) == 0x6000)
  1728. -               te->t_bchtyp = T_UNBR;
  1729. -       else  if  ((tc & 0xff00) == 0x6100)
  1730. -               te->t_bchtyp = T_JSR;
  1731. -       else
  1732. -               te->t_bchtyp = T_CONDBR;
  1733. -
  1734. -       te->t_relsymb = textlab(dest, pos);
  1735. -       return  res;
  1736. -}
  1737. -
  1738. -int    jj(te, pos)
  1739. -t_entry        *te;
  1740. -long   pos;
  1741. -{
  1742. -       unsigned  tc  =  te->t_contents;
  1743. -       t_entry nextl;
  1744. -       
  1745. -       te->t_bchtyp = (tc & 0x40)? T_UNBR: T_JSR;
  1746. -       if  ((tc & 0x3f) == 0x39)  {
  1747. -               gette(&mainfile, pos+2, &nextl);
  1748. -               if  (nextl.t_relsymb == NULL)  {
  1749. -                       nextl.t_relsymb = textlab(gettw(&mainfile, pos+2, R_LONG), pos);
  1750. -                       putte(&mainfile, pos+2, &nextl);
  1751. -               }
  1752. -               te->t_relsymb = nextl.t_relsymb;        /*  Easy ref  */
  1753. -       }
  1754. -       return  lea(tc, 4, pos+2);
  1755. -}
  1756. -
  1757. -int    limed(te, pos)
  1758. -t_entry        *te;
  1759. -long   pos;
  1760. -{
  1761. -       unsigned  tc  =  te->t_contents;
  1762. -       int     lng;
  1763. -       
  1764. -       /*
  1765. -        *      Specifically exclude byte address register operands,
  1766. -        *      and ones which have lengths of 3.
  1767. -        */
  1768. -
  1769. -       if  ((tc & 0xf8) == 0x08)
  1770. -               return  0;
  1771. -       
  1772. -       if  ((tc & 0xc0) >= 0x80)  {
  1773. -               if  (tc &0x40)
  1774. -                       return  0;
  1775. -               lng = lea(tc, 4, pos+6);
  1776. -               if  (lng > 0)
  1777. -                       lng += 2;
  1778. -       }
  1779. -       else  {
  1780. -               lng = lea(tc, (unsigned)((tc & 0xc0)?2:1), pos+4);
  1781. -               if  (lng > 0)
  1782. -                       lng++;
  1783. -       }
  1784. -       return  lng;
  1785. -}
  1786. -
  1787. -int    lsbit(te, pos)
  1788. -t_entry        *te;
  1789. -long   pos;
  1790. -{
  1791. -       int     lng = lea(te->t_contents, 1, pos+4);
  1792. -       
  1793. -       if  (lng > 0)
  1794. -               lng++;
  1795. -       return  lng;
  1796. -}
  1797. -
  1798. -int    lmvml(te, pos)
  1799. -t_entry        *te;
  1800. -long   pos;
  1801. -{
  1802. -       int     lng = lea(te->t_contents,
  1803. -                       (unsigned)(te->t_contents&0x40? 4:2), pos+4);
  1804. -       
  1805. -       if  (lng > 0)
  1806. -               lng++;
  1807. -       return  lng;
  1808. -}
  1809. -
  1810. -/*
  1811. - *     Length depends on bits 6 and 7 of instruction.
  1812. - */
  1813. -
  1814. -int    lone(te, pos)
  1815. -t_entry        *te;
  1816. -long   pos;
  1817. -{
  1818. -       unsigned  tc  =  te->t_contents;
  1819. -       
  1820. -       return  lea(tc, 1 << ((tc >> 6) & 3), pos+2);
  1821. -}
  1822. -
  1823. -/*
  1824. - *     Length depends on bits 6-8 of instruction.
  1825. - */
  1826. -
  1827. -int    loone(te, pos)
  1828. -t_entry        *te;
  1829. -long   pos;
  1830. -{
  1831. -       unsigned  tc  =  te->t_contents;
  1832. -       
  1833. -       switch  ((tc >> 6) & 7)  {
  1834. -       case  0:
  1835. -       case  4:
  1836. -               return  lea(tc, 1, pos+2);
  1837. -       case  1:
  1838. -       case  3:
  1839. -       case  5:
  1840. -               return  lea(tc, 2, pos+2);
  1841. -       case  2:
  1842. -       case  6:
  1843. -       case  7:
  1844. -               return  lea(tc, 4, pos+2);
  1845. -       }
  1846. -       /*NOTREACHED*/
  1847. -}
  1848. -
  1849. -int    lonew(te, pos)
  1850. -t_entry        *te;
  1851. -long   pos;
  1852. -{
  1853. -       return  lea(te->t_contents, 2, pos+2);
  1854. -}
  1855. -
  1856. -int    lonel(te, pos)
  1857. -t_entry        *te;
  1858. -long   pos;
  1859. -{
  1860. -       return  lea(te->t_contents, 4, pos+2);
  1861. -}
  1862. -
  1863. -/*
  1864. - *     Print routines.
  1865. - */
  1866. -
  1867. -int    findleng(tc)
  1868. -unsigned  tc;
  1869. -{
  1870. -       switch  ((tc >> 6) & 3)  {
  1871. -       case  0:
  1872. -               return  'b';
  1873. -       case  1:
  1874. -               return  'w;
  1875. -       default:
  1876. -               return  'l';
  1877. -       }
  1878. -}
  1879. -
  1880. -void   piword(disp)
  1881. -unsigned  disp;
  1882. -{
  1883. -       int     szc;
  1884. -       
  1885. -       (void) printf("@(0x%x,", disp & 0xff);
  1886. -       if  (disp & 0x8000)
  1887. -               (void) printf("%s", areg[(disp >> 12) & 0x7]);
  1888. -       else
  1889. -               (void) printf("d%d", (disp >> 12) & 0x7);
  1890. -       szc = 'w';
  1891. -       if  (disp & (1 << 10))
  1892. -               szc = 'l';
  1893. -       (void) printf(":%c)", szc);
  1894. -}
  1895. -
  1896. -void   paddr(pos)
  1897. -long   pos;
  1898. -{
  1899. -       t_entry tent;
  1900. -       symbol  symb;
  1901. -       
  1902. -       gette(&mainfile, pos, &tent);
  1903. -       if  (tent.t_relsymb != NULL)  {
  1904. -               symb = tent.t_relsymb;
  1905. -               if  (symb->s_lsymb != 0)
  1906. -                       (void) printf("%u$", symb->s_lsymb);
  1907. -               else
  1908. -                       (void) printf("%s", symb->s_name);
  1909. -               if  (tent.t_reldisp != 0)
  1910. -                       (void) printf("+0x%x", tent.t_reldisp);
  1911. -               return;
  1912. -       }
  1913. -       (void) printf("0x%x", gettw(&mainfile, pos, R_LONG));
  1914. -}
  1915. -
  1916. -int    prea(ea, pos, sz)
  1917. -unsigned  ea, sz;
  1918. -long   pos;                    /*  Address of previous word to extn  */
  1919. -{
  1920. -       unsigned  reg  =  ea & 0x7;
  1921. -       long    disp;
  1922. -       
  1923. -       pos += 2;
  1924. -       
  1925. -       switch  ((ea >> 3) & 0x7)  {
  1926. -       case  0:
  1927. -               (void) printf("d%d", reg);
  1928. -               return  0;
  1929. -       case  1:
  1930. -               (void) printf("%s", areg[reg]);
  1931. -               return  0;
  1932. -       case  2:
  1933. -               (void) printf("%s@", areg[reg]);
  1934. -               return  0;
  1935. -       case  3:
  1936. -               (void) printf("%s@+", areg[reg]);
  1937. -               return  0;
  1938. -       case  4:
  1939. -               (void) printf("%s@-", areg[reg]);
  1940. -               return  0;
  1941. -       case  5:
  1942. -               disp = gettw(&mainfile, pos, R_WORD);
  1943. -               (void) printf("%s@(0x%x)", areg[reg], disp);
  1944. -               return  2;
  1945. -       case  6:
  1946. -               (void) printf("%s, areg[reg]);
  1947. -               piword((unsigned) gettw(&mainfile, pos, R_WORD));
  1948. -               return  2;
  1949. -       default:
  1950. -               switch  (reg)  {
  1951. -               case  0:
  1952. -                       disp = gettw(&mainfile, pos, R_WORD);
  1953. -                       (void) printf("0x%x:w", disp);
  1954. -                       return  2;
  1955. -               case  1:
  1956. -                       paddr(pos);
  1957. -                       return  4;
  1958. -               case  2:
  1959. -                       disp = gettw(&mainfile, pos, R_WORD);
  1960. -                       (void) printf("pc@(0x%x)", disp);
  1961. -                       return  2;
  1962. -               case  3:
  1963. -                       (void) printf("pc");
  1964. -                       piword((unsigned) gettw(&mainfile, pos, R_WORD));
  1965. -                       return  2;
  1966. -               case  4:
  1967. -                       (void) printf("#");
  1968. -                       if  (sz < 4)
  1969. -                               (void) printf("0x%x", gettw(&mainfile, pos, R_WORD));
  1970. -                       else
  1971. -                               paddr(pos);
  1972. -                       return  sz;
  1973. -               default:
  1974. -                       (void) fprintf(stderr, "Funny mode\n");
  1975. -                       exit(220);
  1976. -               }
  1977. -       }
  1978. -       /*NOTREACHED*/
  1979. -}
  1980. -       
  1981. -int    pmove(te, pos)
  1982. -t_entry        *te;
  1983. -long   pos;
  1984. -{
  1985. -       unsigned  sz  =  2;
  1986. -       unsigned  tc  =  te->t_contents;
  1987. -       
  1988. -       (void) printf("mov%s\t", optab[te->t_iindex].prarg);
  1989. -       
  1990. -       if  ((tc & 0xf000) == 0x2000)
  1991. -               sz = 4;
  1992. -       
  1993. -       pos += prea(tc, pos, sz);
  1994. -       putchar(',');
  1995. -       (void) prea(((tc >> 9) & 0x7) | ((tc >> 3) & 0x38), pos, sz);
  1996. -}
  1997. -
  1998. -int    pcbch(te)
  1999. -t_entry        *te;
  2000. -{
  2001. -       int     cc = ((te->t_contents >> 8) & 0xf) - 2;
  2002. -       char    *msg;
  2003. -       register  symbol  ts;
  2004. -       
  2005. -       if  (cc < 0)
  2006. -               msg = cc < -1? "ra": "sr";
  2007. -       else
  2008. -               msg = cclist[cc];
  2009. -       (void) printf("b%s",msg);
  2010. -       if  (te->t_lng < 2)
  2011. -               (void) printf("s");
  2012. -       ts = te->t_relsymb;
  2013. -       if  (ts->s_lsymb != 0)
  2014. -               (void) printf("\t%u$", ts->s_lsymb);
  2015. -       else
  2016. -               (void) printf("\t%s", ts->s_name);
  2017. -}
  2018. -
  2019. -int    pdbcc(te)
  2020. -t_entry        *te;
  2021. -{
  2022. -       unsigned  tc  =  te->t_contents;
  2023. -       int     cc = ((tc >> 8) & 0xf) - 2;
  2024. -       char    *msg;
  2025. -       register  symbol  ts;
  2026. -       
  2027. -       if  (cc < 0)
  2028. -               msg = cc < -1? "t": "f";
  2029. -       else
  2030. -               msg = cclist[cc];
  2031. -       ts = te->t_relsymb;
  2032. -       (void) printf("db%s\td%d,", msg, tc & 0x7);
  2033. -       if  (ts->s_lsymb)
  2034. -               (void) printf("%u$", ts->s_lsymb);
  2035. -       else
  2036. -               (void) printf("%s", ts->s_name);
  2037. -}
  2038. -
  2039. -int    pscc(te, pos)
  2040. -t_entry        *te;
  2041. -long   pos;
  2042. -{
  2043. -       unsigned  tc  =  te->t_contents;
  2044. -       int     cc = ((tc >> 8) & 0xf) - 2;
  2045. -       char    *msg;
  2046. -       
  2047. -       if  (cc < 0)
  2048. -               msg = cc < -1? "t": "f";
  2049. -       else
  2050. -               msg = cclist[cc];
  2051. -       (void) printf("s%s\t", msg);
  2052. -       (void) prea(tc, pos, 1);
  2053. -}
  2054. -
  2055. -int    pcs(te, pos)
  2056. -t_entry        *te;
  2057. -long   pos;
  2058. -{
  2059. -       long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  2060. -       
  2061. -       (void) printf("%s", optab[te->t_iindex].prarg);
  2062. -       if  ((te->t_contents & 0xc0) == 0)
  2063. -               (void) printf("b\t#0x%x,cc", disp);
  2064. -       else
  2065. -               (void) printf("w\t#0x%x,sr", disp);
  2066. -}
  2067. -
  2068. -int    pmovc(te, pos)
  2069. -t_entry        *te;
  2070. -long   pos;
  2071. -{
  2072. -       int     disp = gettw(&mainfile, pos+2, R_WORD);
  2073. -       int     ctrl = ((disp >> 10) & 2) | (disp & 1);
  2074. -
  2075. -       (void) printf("movec\t");
  2076. -       if  ((te->t_contents & 1) == 0)
  2077. -               (void) printf("%s,", creg[ctrl]);
  2078. -       if  (disp & 0x8000)
  2079. -               (void) printf("%s", areg[(disp >> 12) & 7]);
  2080. -       else
  2081. -               (void) printf("d%d", disp >> 12);
  2082. -       if  (te->t_contents & 1)
  2083. -              (void) printf(",%s", creg[ctrl]);
  2084. -}
  2085. -
  2086. -int    pimed(te, pos)
  2087. -t_entry        *te;
  2088. -long   pos;
  2089. -{
  2090. -       int     sz = findleng(te->t_contents);
  2091. -       
  2092. -       (void) printf("%s%c\t#", optab[te->t_iindex].prarg, sz);
  2093. -       if  (sz == 'l')  {
  2094. -               paddr(pos+2);
  2095. -               putchar(',');
  2096. -               (void) prea(te->t_contents, pos+4, 4);
  2097. -       }
  2098. -       else  {
  2099. -               (void) printf("0x%x,", gettw(&mainfile, pos+2, R_WORD));
  2100. -               (void) prea(te->t_contents, pos+2, 2);
  2101. -       }
  2102. -}
  2103. -
  2104. -int    pmovp(te, pos)
  2105. -t_entry        *te;
  2106. -long   pos;
  2107. -{
  2108. -       unsigned  tc  =  te->t_contents;
  2109. -       long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  2110. -       int     dreg = tc >> 9;
  2111. -       char    *ar = areg[tc & 0x7];
  2112. -       
  2113. -       (void) printf("movep");
  2114. -       if  (tc & (1 << 6))
  2115. -               putchar('l');
  2116. -       else
  2117. -               putchar('w');
  2118. -
  2119. -       if  (tc & (1 << 7))
  2120. -               (void) printf("\td%d,%s@(0x%x)", dreg, ar, disp);
  2121. -       else
  2122. -               (void) printf("\t%s@(0x%x),d%d", ar, disp, dreg);
  2123. -}
  2124. -
  2125. -int    psbit(te, pos)
  2126. -t_entry        *te;
  2127. -long   pos;
  2128. -{
  2129. -       unsigned  tc  =  te->t_contents;
  2130. -       
  2131. -       (void) printf("b%s\t#%d,", bittyp[(tc >> 6) & 0x3], gettw(&mainfile, pos+2, R_WORD));
  2132. -       (void) prea(tc, pos+2, 1);
  2133. -}
  2134. -
  2135. -/*ARGSUSED*/
  2136. -int    pstop(te, pos)
  2137. -t_entry        *te;
  2138. -long   pos;
  2139. -{
  2140. -       (void) printf("stop\t#0x%x", gettw(&mainfile, pos+2, R_WORD));
  2141. -}
  2142. -
  2143. -int    pdbit(te, pos)
  2144. -t_entry        *te;
  2145. -long   pos;
  2146. -{
  2147. -       unsigned  tc  =  te->t_contents;
  2148. -       
  2149. -       (void) printf("b%s\td%d,", bittyp[(tc >> 6) & 0x3], (tc >> 9) & 0x7);
  2150. -       (void) prea(tc, pos, 1);
  2151. -}
  2152. -
  2153. -int    pcs2(te, pos)
  2154. -t_entry        *te;
  2155. -long   pos;
  2156. -{
  2157. -       unsigned  tc  =  te->t_contents;
  2158. -       
  2159. -       (void) printf("movw\t");
  2160. -       if  ((tc & 0xffc0) == 0x40c0)  {
  2161. -               (void) printf("sr,");
  2162. -               (void) prea(tc, pos, 2);
  2163. -      }
  2164. -       else  {
  2165. -               (void) prea(tc, pos, 2);
  2166. -               (void) printf(",%s", optab[te->t_iindex].prarg);
  2167. -       }
  2168. -}
  2169. -
  2170. -int    pone(te, pos)
  2171. -t_entry        *te;
  2172. -long   pos;
  2173. -{
  2174. -       unsigned  tc  =  te->t_contents;
  2175. -       int     sz = findleng(tc);
  2176. -       
  2177. -       (void) printf("%s%c\t", optab[te->t_iindex].prarg, sz);
  2178. -       (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  2179. -}
  2180. -
  2181. -int    ppea(te, pos)   /*  nbcd, pea, tas, jmp, jsr  */
  2182. -t_entry        *te;
  2183. -long   pos;
  2184. -{
  2185. -       (void) printf("%s\t", optab[te->t_iindex].prarg);
  2186. -       (void) prea(te->t_contents, pos, (unsigned)(te->t_lng > 2? 4: 2));
  2187. -}
  2188. -
  2189. -
  2190. -int    plea(te, pos)
  2191. -t_entry        *te;
  2192. -long   pos;
  2193. -{
  2194. -       (void) printf("lea\t");
  2195. -       (void) prea(te->t_contents, pos, 4);
  2196. -       (void) printf(",%s", areg[(te->t_contents >> 9) & 0x7]);
  2197. -}
  2198. -
  2199. -int    pdreg(te)
  2200. -t_entry        *te;
  2201. -{
  2202. -       (void) printf("%s\td%d", optab[te->t_iindex].prarg, te->t_contents & 7);-}
  2203. -
  2204. -
  2205. -int    pmvml(te, pos)
  2206. -t_entry        *te;
  2207. -long   pos;
  2208. -{
  2209. -       unsigned  tc  =  te->t_contents;
  2210. -       register  unsigned  dw  =  gettw(&mainfile, pos+2, R_WORD);
  2211. -       unsigned  sz = 4;
  2212. -       int     sc = 'l';
  2213. -       register  int   i;
  2214. -       register  unsigned  bit;
  2215. -       
  2216. -       (void) printf("movem");
  2217. -       if  ((tc & 0x40) == 0)  {
  2218. -               sc = 'w';
  2219. -               sz = 2;
  2220. -       }
  2221. -       
  2222. -       (void) printf("%c\t", sc);
  2223. -       
  2224. -       if  (tc & 0x400)  {
  2225. -               (void) prea(tc, pos+2, sz);
  2226. -               (void) printf(",#0x%x", dw);
  2227. -       }
  2228. -       else  {
  2229. -               (void) printf("#0x%x,", dw);
  2230. -               (void) prea(tc, pos+2, sz);
  2231. -       }
  2232. -       
  2233. -       (void) printf("\t|");
  2234. -       
  2235. -       if  ((tc & 0x38) == 0x20)  {
  2236. -               bit = 0x8000;
  2237. -               for  (i = 0;  i < 8;  i++)  {
  2238. -                       if  (dw & bit)
  2239. -                               (void) printf(" d%d", i);
  2240. -                      bit >>= 1;
  2241. -               }
  2242. -               for  (i = 0;  i < 8;  i++)  {
  2243. -                       if  (dw & bit)
  2244. -                               (void) printf(" %s", areg[i]);
  2245. -                       bit >>= 1;
  2246. -               }
  2247. -       }
  2248. -       else  {
  2249. -               bit = 1;
  2250. -               for  (i = 0;  i < 8;  i++)  {
  2251. -                       if  (dw & bit)
  2252. -                               (void) printf(" d%d", i);
  2253. -                       bit <<= 1;
  2254. -               }
  2255. -               for  (i = 0;  i < 8;  i++)  {
  2256. -                       if  (dw & bit)
  2257. -                               (void) printf(" %s", areg[i]);
  2258. -                       bit <<= 1;
  2259. -               }
  2260. -       }
  2261. -}
  2262. -
  2263. -int    ptrap(te)
  2264. -t_entry        *te;
  2265. -{
  2266. -       (void) printf("trap\t#0x%x", te->t_contents & 0xf);
  2267. -}
  2268. -
  2269. -int    plink(te, pos)
  2270. -t_entry        *te;
  2271. -long   pos;
  2272. -{
  2273. -       (void) printf("link\t%s,#0x%x", areg[te->t_contents & 0x7],
  2274. -                               gettw(&mainfile, pos+2, R_WORD));
  2275. -}
  2276. -
  2277. -
  2278. -int    pareg(te)
  2279. -t_entry        *te;
  2280. -{
  2281. -       (void) printf(optab[te->t_iindex].prarg, areg[te->t_contents & 0x7]);
  2282. -}
  2283. -
  2284. -int    podreg(te, pos)
  2285. -t_entry        *te;
  2286. -long   pos;
  2287. -{
  2288. -       unsigned  tc  =  te->t_contents;
  2289. -       
  2290. -       (void) printf("%s\t", optab[te->t_iindex].prarg);
  2291. -       (void) prea(tc, pos, 2);
  2292. -       (void) printf(",d%d", (tc >> 9) & 0x7);
  2293. -}
  2294. -
  2295. -int    pqu(te, pos)
  2296. -t_entry        *te;
  2297. -long   pos;
  2298. -{
  2299. -       unsigned  tc  =  te->t_contents;
  2300. -       int     sz  =  findleng(tc);
  2301. -       int     amt = (tc >> 9) & 0x7;
  2302. -       
  2303. -       if  (amt == 0)
  2304. -               amt = 8;
  2305. -       (void) printf("%sq%c\t#%d,", optab[te->t_iindex].prarg, sz, amt);
  2306. -       (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  2307. -}
  2308. -
  2309. -int    pmqu(te)
  2310. -t_entry        *te;
  2311. -{
  2312. -       unsigned  tc  =  te->t_contents;
  2313. -
  2314. -       (void) printf("moveq\t#0x%x,d%d", (char)tc, (tc >> 9) & 0x7);
  2315. -}
  2316. -
  2317. -int    ptreg(te)
  2318. -t_entry        *te;
  2319. -{
  2320. -       regster  unsigned  tc  =  te->t_contents;
  2321. -       int     rx = (tc >> 9) & 0x7;
  2322. -       int     ry = tc & 0x7;
  2323. -
  2324. -       (void) printf("%s\t", optab[te->t_iindex].prarg);
  2325. -       if  (tc & 0x8)
  2326. -               (void) printf("%s@-,%s@-", areg[ry], areg[rx]);
  2327. -       else
  2328. -               (void) printf("d%d,d%d", ry, rx);
  2329. -}
  2330. -
  2331. -int    pcmpm(te)
  2332. -t_entry        *te;
  2333. -{
  2334. -       register  unsigned  tc  =  te->t_contents;
  2335. -
  2336. -       (void) printf("%s\t%s@+,%s@+", optab[te->t_iindex].prarg,
  2337. -               areg[tc & 7], areg[(tc >> 9) & 7]);
  2338. -}
  2339. -
  2340. -int    pomode(te, pos)
  2341. -t_entry        *te;
  2342. -long   pos;
  2343. -{
  2344. -       unsigned  tc  =  te->t_contents;
  2345. -       char    bef[4], aft[4];
  2346. -       int     sz;
  2347. -       int     reg = (tc >> 9) & 7;
  2348. -
  2349. -       bef[0] = aft[0] = '\0';
  2350. -       
  2351. -       switch  ((tc >> 6) & 7)  {
  2352. -       case  0:
  2353. -               sz = 'b';
  2354. -               goto  toreg;
  2355. -       case  1:
  2356. -               sz = 'w';
  2357. -               goto  toreg;
  2358. -       case  2:
  2359. -               sz = 'l';
  2360. -       toreg:
  2361. -               (void) sprintf(aft, ",d%d", reg);
  2362. -               break;
  2363. -       case  3:
  2364. -               sz = 'w';
  2365. -               goto  toareg;
  2366. -       case  7:
  2367. -               sz = 'l';
  2368. -       toareg:
  2369. -               (void) sprintf(aft, ",%s", areg[reg]);
  2370. -               break;
  2371. -       case  4:
  2372. -               sz = 'b';
  2373. -               goto  frreg;
  2374. -       case  5:
  2375. -               sz = 'w';
  2376. -               goto  frreg;
  2377. -       case  6:
  2378. -               sz = 'l';
  2379. -       frreg:
  2380. -               (void) sprintf(bef, "d%d,", reg);
  2381. -               break;
  2382. -       }
  2383. -
  2384. -       (void) printf("%s%c\t%s", optab[te->t_iindex].prarg, sz, bef);
  2385. -       (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  2386. -       (void) printf(aft);
  2387. -}
  2388. -
  2389. -int    pexg(te)
  2390. -t_entry        *te;
  2391. -{
  2392. -       unsigned  tc  =  te->t_contents;
  2393. -       int     r1 = (tc >> 9) & 7, r2 = tc & 7;
  2394. -
  2395. -       (void) printf("exg\t");
  2396. -       
  2397. -       if  ((tc & 0x00f8) == 0x0048)
  2398. -              (void) printf("%s,", areg[r1]);
  2399. -       else
  2400. -               (void) printf("d%d,", r1);
  2401. -       if  (tc & 0x8)
  2402. -               (void) printf("%s", areg[r2]);
  2403. -       else
  2404. -               (void) printf("d%d", r2);
  2405. -}
  2406. -       
  2407. -int    pmshf(te, pos)
  2408. -t_entry        *te;
  2409. -long   pos;
  2410. -{
  2411. -       unsigned  tc  =  te->t_contents;
  2412. -       
  2413. -       (void) printf("%s%cw\t", shtype[(tc >> 9) & 3], tc & 0x100? 'l': 'r');
  2414. -       (void) prea(tc, pos, 2);
  2415. -}
  2416. -
  2417. -int    pshf(te)
  2418. -t_entry        *te;
  2419. -{
  2420. -       unsigned  tc  =  te->t_contents;
  2421. -       int     sz  =  findleng(tc);
  2422. -       int     disp = (tc >> 9) & 7;
  2423. -
  2424. -       (void) printf("%s%c%c\t", shtype[(tc >> 3) & 3], tc & 0x100? 'l': 'r', sz);
  2425. -       if  (tc & 0x20)
  2426. -               (void) printf("d%d", disp);
  2427. -       else
  2428. -               (void) printf("#%d", disp == 0? 8: disp);
  2429. -       (void) printf(",d%d", tc & 7);
  2430. -}
  2431. -
  2432. -/*
  2433. - *     Find length etc of instruction.
  2434. - */
  2435. -
  2436. -int    findinst(te, pos)
  2437. -register  t_entry  *te;
  2438. -long   pos;
  2439. -{
  2440. -       register  struct  opstr *op;
  2441. -       unsigned  tc  =  te->t_contents;
  2442. -       int     lng = 0;
  2443. -       register  int   i;
  2444. -
  2445. -       te->t_type = T_BEGIN;
  2446. -       te->t_bchtyp = T_NOBR;
  2447. -       
  2448. -       for  (op = &optab[0];  op->mask;  op++)  {
  2449. -               if  ((tc & op->mask) == op->match)  {
  2450. -                       te->t_iindex = op - optab;
  2451. -                       lng = (op->opsize)(te, pos);
  2452. -                       break;
  2453. -               }
  2454. -       }
  2455. -
  2456. -       for  (i = 1;  i < lng;  i++)  {
  2457. -               t_entry ctent;
  2458. -               long    npos = pos+i+i;
  2459. -               
  2460. -               if  (npos >= endt)
  2461. -                       goto  clearem;
  2462. -               gette(&mainfile, npos, &ctent);
  2463. -               if  (ctent.t_bdest || ctent.t_dref)  {
  2464. -clearem:               for  (i--; i > 0; i--)  {
  2465. -                               npos = pos + i + i;
  2466. -                               gette(&mainfile, npos, &ctent);
  2467. -                               ctent._type = T_UNKNOWN;
  2468. -                               putte(&mainfile, npos, &ctent);
  2469. -                       }
  2470. -                       lng = 0;
  2471. -                       goto  ginv;
  2472. -               }
  2473. -               ctent.t_type = T_CONT;
  2474. -               putte(&mainfile, npos, &ctent);
  2475. -       }
  2476. -       
  2477. -       if  (lng <= 0)  {
  2478. -ginv:          te->t_vins = 0;
  2479. -               te->t_lng = 1;
  2480. -               te->t_type = T_UNKNOWN;
  2481. -               te->t_bchtype = T_NOBR;
  2482. -       }
  2483. -       else
  2484. -               te->t_lng = lng;
  2485. -       return  lng;
  2486. -}
  2487. -
  2488. -/*
  2489. - *     Print instruction.
  2490. - */
  2491. -
  2492. -void   prinst(te, pos)
  2493. -t_entry        *te;
  2494. -long   pos;
  2495. -{
  2496. -       putchar('\t');
  2497. -       (optab[te->t_iindex].opprin)(te, pos);
  2498. -       putchar('\n');
  2499. -}
  2500. //GO.SYSIN DD iset.c
  2501. echo libmtch.c 1>&2
  2502. sed 's/.//' >libmtch.c <<'//GO.SYSIN DD libmtch.c'
  2503. -/*
  2504. - *     SCCS:   @(#)libmtch.c   1.2     11/2/84 14:18:55
  2505. - *     Read library files.
  2506. - *
  2507. - ***********************************************************************
  2508. - *     This software is copyright of
  2509. - *
  2510. - *             John M Collins
  2511. - *             47 Cedarwood Drive
  2512. - *             St Albans
  2513. - *             Herts, AL4 0DN
  2514. - *             England                 +44 727 57267
  2515. - *
  2516. - *     and is released into the public domain on the following conditions:
  2517. - *
  2518. - *             1.  No free maintenance will be guaranteed.
  2519. - *             2.  Nothing may be based on this software without
  2520. - *                 acknowledgement, including incorporation of this
  2521. - *                 notice.
  2522. - *
  2523. - *     Notwithstanding the above, the author welcomes correspondence and bug
  2524. - *     fixes.
  2525. - ***********************************************************************
  2526. - */
  2527. -
  2528. -#include <stdio.h>
  2529. -#include <fcntl.h>
  2530. -#include <a.out.h>
  2531. -#include <ar.h>
  2532. -#include <setjmp.h>
  2533. -#include "unc.h"
  2534. -
  2535. -long   lseek();
  2536. -void   bfopen(), bfclose(), nomem();
  2537. -void   rrell2(), markmatch();
  2538. -char   *strchr(), *strrchr(), *strncpy(), *strcat(), *strcpy(, *malloc();
  2539. -int    matchup();
  2540. -long   findstart();
  2541. -
  2542. -char   verbose;                /*  Tell the world what we are doing  */
  2543. -char   *tfnam;
  2544. -char   *cfile;
  2545. -ef_fids        mainfile;
  2546. -struct commit  dreltab;
  2547. -int    donedrel, donebrel;
  2548. -long   trelpos, drelpos, brelpos;
  2549. -static struct  libit   currlib = {-1, 0, -1, ""};
  2550. -
  2551. -void   lclash(str)
  2552. -char   *str;
  2553. -{
  2554. -       (void) fprintf(stderr, "Library scan failure - %s\n", str);
  2555. -       (void) fprintf(stderr, "Searching %s\n", cfile);
  2556. -       if  (currlib.lf_name[0])
  2557. -               (void) fprintf(stderr, "Member is %s\n", currlib.lf_name);
  2558. -       exit(255);
  2559. -}
  2560. -
  2561. -/*
  2562. - *     Find next member.
  2563. - */
  2564. -
  2565. -long   nextmemb(lfd)
  2566. -register  struct  libit         *lfd;
  2567. -{
  2568. -       struct  ar_hdr  arbuf;
  2569. -       
  2570. -       if  (lfd->lf_next < 0)
  2571. -               return  -1;
  2572. -       
  2573. -       (void) lseek(lfd->lf_fd, lfd->lf_next, 0);
  2574. -       if  (read(lfd->lf_fd, (char *)&arbuf, sizeof(arbuf)) != sizeof(arbuf))  {
  2575. -               lfd->lf_next = -1;
  2576. -               return  -1;
  2577. -       }
  2578. -       (void) strncpy(lfd->lf_name, arbuf.ar_name, sizeof(lfd->lf_name));
  2579. -       lfd->lf_offset = lfd->lf_next + sizeof(arbuf);
  2580. -       lfd->lf_next = (lfd->lf_offset + arbuf.ar_size + 1) & ~1;
  2581. -       return  lfd->lf_offset;
  2582. -}
  2583. -
  2584. -/*
  2585. - *     Decode a file name thus -
  2586. - *
  2587. - *     -lxxx decode as /lib/libxxx.a /usr/lib/libxxx.a etc
  2588. - *     -Lxxx forget "lib" ".a" bit thus -Lcrt0.o
  2589. - *     or read LDPATH environment var to give list of directories as sh
  2590. - *     (default /lib:/usr/lib).
  2591. - *
  2592. - *     Alternatively treat as normal pathname.
  2593. - *
  2594. - *     File names may be followed by (membername) if the file is an archive,
  2595. - *     thus
  2596. - *
  2597. - *             -lc(printf.o)
  2598. - *
  2599. - *     in which case the specified module is fetched.
  2600. - */
  2601. -
  2602. -struct libit   *getfnam(str)
  2603. -char   *str;
  2604. -{
  2605. -       char    *bp, *ep = NULL, *pathb, *pathe, *fullpath = NULL;
  2606. -       static  char    *pathn;
  2607. -       extern  char    *getenv();
  2608. -       long    magic;
  2609. -       struct  ar_hdr  arhdr;
  2610. -       int     fd;
  2611. -
  2612. -       if  ((bp = strrchr(str, '(')) != NULL &&
  2613. -                (ep = strrchr(str, ')')) != NULL)
  2614. -               *ep = *bp = '\0';
  2615. -
  2616. -       if  (str[0] == '-'  &&  (str[1] == 'l' || str[1] == 'L'))  {
  2617. -               if  (pathn == NULL)  {
  2618. -                       if  ((pathn = getenv("LDPATH")) == NULL)
  2619. -                               pathn = "/lib:/usr/lib";
  2620. -               }
  2621. -               fullpath = malloc((unsigned)(strlen(pathn) + strlen(str) + 1));
  2622. -               if  (fullpath == NULL)
  2623. -                       nomem();
  2624. -               pathb = pathn;
  2625. -               do  {
  2626. -                       pathe = strchr(pathb, ':');
  2627. -                       if  (*pathb == ':')
  2628. -                               fullpath[0] = '\0';
  2629. -                       else  {
  2630. -                               if  (pathe != NULL)
  2631. -                                       *pathe = '\0';
  2632. -                               (void) strcpy(fullpath, pathb);
  2633. -                               (void) strcat(fullpath, "/");
  2634. -                               if  (pathe != NULL)
  2635. -                                       *pathe = ':';
  2636. -                       }
  2637. -                       if  (str[1] == 'l')
  2638. -                               (void) strcat(fullpath, "lib");
  2639. -                       (void) strcat(fullpath, &str[2]);
  2640. -                       if  (str[1] == 'l')
  2641. -                               (void) strcat(fullpath, ".a");
  2642. -                       if  ((fd = open(fullpath, O_RDONLY)) >= 0)
  2643. -                               goto  found;
  2644. -                       pathb = pathe + 1;
  2645. -               }   while  (pathe != NULL);
  2646. -               
  2647. -               (void) fprintf(stderr, "Unable to locate lib%s.a in %s\n",
  2648. -                       &str[2], pathn);
  2649. -               exit(101);
  2650. -       }
  2651. -       else  if  ((fd = open(str, O_RDONLY)) < 0)  {
  2652. -               (void) fprintf(stderr, "Cannot open %s\n", str);
  2653. -               exit(102);
  2654. -       }
  2655. -       
  2656. -found:
  2657. -
  2658. -       if  ((read(fd, (char *) &magic, sizeof(magic)) != sizeof(magic)  ||
  2659. -               magic != ARMAG))  {
  2660. -               if  (ep != NULL)  {
  2661. -                       (void) fprintf(stderr, "%s is not library file\n",
  2662. -                                       fullpath != NULL? fullpath: str);
  2663. -                       exit(103);
  2664. -               }
  2665. -               if  (fullpath != NULL)
  2666. -                       free(fullpath);
  2667. -               currlib.lf_fd = fd;
  2668. -               currlib.lf_offset = 0;
  2669. -               currlib.lf_next = -1;
  2670. -               currlib.lf_name[0] = '\0';
  2671. -               return  &currlib;
  2672. -       }
  2673. -       
  2674. -       /*
  2675. -        *      It appears to be a library file - see if we want a specific
  2676. -        *      one.
  2677. -        */
  2678. -       
  2679. -       if  (ep != NULL)  {
  2680. -               currlib.lf_offset = sizeof(magic) + sizeof(struct ar_hdr);
  2681. -               for  (;;)  {
  2682. -                       if  (read(fd, &arhdr, sizeof(arhdr)) != sizeof(arhdr))  {
  2683. -                               (void) fprintf(stderr, "Cannot find member %s in %s\n",
  2684. -                                       bp+1, fullpath?fullpath: str);
  2685. -                               exit(103);
  2686. -                       }
  2687. -                       if  (strncmp(bp+1, arhdr.ar_name, sizeof(arhdr.ar_name)) == 0)
  2688. -                               break;
  2689. -                       currlib.lf_offset += arhdr.ar_size + sizeof(arhdr) + 1;
  2690. -                       currlib.lf_offset &= ~ 1;
  2691. -                       (void) lseek(fd, (long)(currlib.lf_offset - sizeof(arhdr)), 0);
  2692. -               }
  2693. -               if  (fullpath != NULL)
  2694. -                       free(fullpath);
  2695. -               currlib.lf_fd = fd;
  2696. -               currlib.lf_next = -1;
  2697. -               currlib.lf_name[0] = '\0';
  2698. -               *bp = '(';
  2699. -               *ep = ')';
  2700. -               return  &currlib;
  2701. -       }
  2702. -       
  2703. -       /*
  2704. -        *      Otherwise point to 1st member in library.
  2705. -        */
  2706. -       
  2707. -       if  (read(fd, &arhdr, szeof(arhdr)) != sizeof(arhdr))  {
  2708. -               (void) fprintf(stderr, "Library %s empty\n", fullpath? fullpath: str);
  2709. -               exit(104);
  2710. -       }
  2711. -       if  (fullpath != NULL)
  2712. -               free(fullpath);
  2713. -       currlib.lf_offset = sizeof(magic) + sizeof(arhdr);
  2714. -       currlib.lf_next = currlib.lf_offset + arhdr.ar_size + 1;
  2715. -       currlib.lf_next &= ~1;
  2716. -       currlib.lf_fd = fd;
  2717. -       (void) strncpy(currlib.lf_name, arhdr.ar_name, sizeof(currlib.lf_name));-       return  &currlib;
  2718. -}
  2719. -
  2720. -/*
  2721. - *     Process library files.
  2722. - */
  2723. -
  2724. -#define        MINTEXT 6
  2725. -
  2726. -void   lscan(nfiles, fnames)
  2727. -int    nfiles;
  2728. -char   **fnames;
  2729. -{
  2730. -       ef_fids libfile;
  2731. -       register  ef_fid  ll = &libfile;
  2732. -       register  struct  libit  *clf;
  2733. -       extern  symbol  dolsymb();
  2734. -       int     firstfile;
  2735. -       
  2736. -       for  (;  nfiles > 0;  fnames++, nfiles--)  {
  2737. -               clf = getfnam(*fnames);
  2738. -               cfile = *fnames;
  2739. -               firstfile = 1;
  2740. -               do  {
  2741. -                       bfopen(tfnam, ll);
  2742. -
  2743. -                       /*
  2744. -                        *      If file is garbled, silently forget it and go
  2745. -                        *      on to the next one.
  2746. -                        */
  2747. -
  2748. -                       if  (!rtext(clf->lf_fd, clf->lf_offset, ll))
  2749. -                               goto  closeit;
  2750. -                               
  2751. -                       if  (ll->ef_tsize < MINTEXT)
  2752. -                               goto  closeit;
  2753. -                               
  2754. -                       if  (!rdata(clf->lf_fd, clf->lf_offset, ll))
  2755. -                               goto  closeit;
  2756. -                               
  2757. -                       if  (rrell1(clf->lf_fd, clf->lf_offset, ll) < 0)
  2758. -                               goto  closeit;
  2759. -                               
  2760. -                       /*
  2761. -                        *      If first file in library, find it from
  2762. -                        *      beginning of main file.
  2763. -                       */
  2764. -                       
  2765. -                       if  (firstfile)  {
  2766. -                               if  ((trelpos = findstart(&mainfile, ll)) < 0)
  2767. -                                       goto  closeit;
  2768. -                               firstfile = 0;
  2769. -                       }
  2770. -                       else   if  (!matchup(&mainfile, ll, trelpos))
  2771. -                                       goto  closeit;
  2772. -                       
  2773. -                       /*
  2774. -                        *      Found a match.
  2775. -                        */
  2776. -                       
  2777. -                       if  (!rsymb(clf->lf_fd, clf->lf_offset, dolsymb, ll))  {-                               (void) fprintf(stderr, "Corrupt file %s\n",
  2778. -                                                       *fnames);
  2779. -                               exit(150);
  2780. -                       }
  2781. -                       
  2782. -                       donedrel = 0;
  2783. -                       donebrel = 0;
  2784. -                       rrell2(clf->lf_fd, clf->lf_offset, ll);
  2785. -                       if  (verbose)  {
  2786. -                               (void) fprintf(stderr, "Found: ");
  2787. -                               if  (clf->lf_name[0])
  2788. -                                       (void) fprintf(stderr, "%.14s in ",
  2789. -                                                       clf->lf_name);
  2790. -                               (void) fprintf(stderr, "%s\n", *fnames);
  2791. -                       }
  2792. -                       if  (libfile.ef_stvec != NULL)  {
  2793. -                               free(libfile.ef_stvec);
  2794. -                               libfile.ef_stvec = NULL;
  2795. -                               libfile.ef_stcnt = 0;
  2796. -                       }
  2797. -                       dreltab.c_int = 0;
  2798. -                               
  2799. -                       /*
  2800. -                        *      Start looking next time round
  2801. -                        *      where last one left off.
  2802. -                        */
  2803. -                       
  2804. -                       markmatch(&mainfile, ll, trelos);
  2805. -                       trelpos += libfile.ef_tsize;
  2806. -closeit:
  2807. -                       bfclose(ll);
  2808. -               }  while  (nextmemb(clf) >= 0);
  2809. -       }
  2810. -}
  2811. //GO.SYSIN DD libmtch.c
  2812. echo main.c 1>&2
  2813. sed 's/.//' >main.c <<'//GO.SYSIN DD main.c'
  2814. -/*
  2815. - *     SCCS:   @(#)main.c      1.2     11/2/84 14:19:31
  2816. - *     Main routine etc.
  2817. - *
  2818. - ***********************************************************************
  2819. - *     This software is copyright of
  2820. - *
  2821. - *             John M Collins
  2822. - *             47 Cedarwood Drive
  2823. - *             St Albans
  2824. - *             Herts, AL4 0DN
  2825. - *             England                 +44 727 57267
  2826. - *
  2827. - *     and is released into the public domain on the following conditions:
  2828. - *
  2829. - *             1.  No free maintenance will be guaranteed.
  2830. - *             2.  Nothing may be based on this software without
  2831. - *                 acknowledgement, including incorporation of this
  2832. - *                 notice.
  2833. - *
  2834. - *     Notwithstanding the above, the author welcomes correspondence and bug
  2835. - *     fixes.
  2836. - ***********************************************************************
  2837. - */
  2838. -
  2839. -#include <stdio.h>
  2840. -#include <fcntl.h>
  2841. -#include <a.out.h>
  2842. -#include <sys/var.h>
  2843. -#include "unc.h"
  2844. -
  2845. -#define        LINELNG 70
  2846. -
  2847. -void   inturdat(), intutext(), intudat(), intlsym();
  2848. -void   ptext(), pdata(), pabs(), pbss(), lscan();
  2849. -
  2850. -ef_fids        mainfile;
  2851. -
  2852. -int    par_entry, par_round;   /*  68000 parameters  */
  2853. -int    nmods;                  /*  Number of modules it looks like  */
  2854. -
  2855. -char   *tfnam = "split";
  2856. -
  2857. -char   lsyms;                  /*  Generate local symbols  */
  2858. -char   verbose;                /*  Tell the world what we are doing  */
  2859. -char   noabs;                  /*  No non-global absolutes  */
  2860. -int    rel;                    /*  File being analysed is relocatable  */
  2861. -int    lpos;
  2862. -
  2863. -symbol dosymb();
  2864. -struct libit   *getfnam();
  2865. -
  2866. -/*
  2867. - *     Get hex characters, also allowing for 'k' and 'm'.
  2868. - */
  2869. -
  2870. -int    ghex(str)
  2871. -registe  char *str;
  2872. -{
  2873. -       register  int   result = 0;
  2874. -       register  int   lt;
  2875. -
  2876. -       for  (;;)  {
  2877. -               lt = *str++;
  2878. -               switch  (lt)  {
  2879. -               default:
  2880. -err:                   (void) fprintf(stderr, "Invalid hex digit \'%c\'\n", lt);
  2881. -                       exit(1);
  2882. -                       
  2883. -               case '\0':
  2884. -                       return  result;
  2885. -                       
  2886. -               case '0':case '1':case '2':case '3':case '4':
  2887. -               case '5':case '6':case '7':case '8':case '9':
  2888. -                       result = (result << 4) + lt - '0';
  2889. -                       continue;
  2890. -                       
  2891. -               case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
  2892. -                       result = (result << 4) + lt - 'a' + 10;
  2893. -                       continue;
  2894. -
  2895. -               case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
  2896. -                       result = (result << 4) + lt - 'A' + 10;
  2897. -                       continue;
  2898. -               
  2899. -               case 'k':case 'K':
  2900. -                       if  (*str != '\0')
  2901. -                               goto  err;
  2902. -                       return  result << 10;
  2903. -                       
  2904. -               case 'm':case 'M':
  2905. -                       if  (*str != '\0')
  2906. -                               goto  err;
  2907. -                       return  result << 20;
  2908. -               }
  2909. -       }
  2910. -}
  2911. -
  2912. -/*
  2913. - *     Process entry line options.  Return number dealt with.
  2914. - */
  2915. -
  2916. -int    doopts(av)
  2917. -char   *av[];
  2918. -{
  2919. -       register  int   cnt = 0, lt;
  2920. -       register  char  *arg;
  2921. -       struct  var     vs;
  2922. -       
  2923. -       uvar(&vs);
  2924. -       par_entry = vs.v_ustart;
  2925. -       par_round = vs.v_txtrnd - 1;
  2926. -       
  2927. -       for  (;;)  {
  2928. -               arg = *++av;
  2929. -               if  (*arg++ != '-')
  2930. -                       return  cnt;
  2931. -               cnt++;
  2932. -               
  2933. -nx:            switch  (lt = *arg++)  {
  2934. -               default:
  2935. -                       (void)fprintf(stderr, "Bad option -%c\n", lt);
  2936. -                       exit(1);
  2937. -                       
  2938. -               case  '\0':
  2939. -                       continue;
  2940. -                       
  2941. -               case  'l':      /*  A file name  */
  2942. -               case  'L':
  2943. -                       return  cnt - 1;
  2944. -                       
  2945. -               case  's':
  2946. -                       lsyms++;
  2947. -                       goto  nx;
  2948. -                       
  2949. -               case  'v':
  2950. -                       verbose++;
  2951. -                       goto  nx;
  2952. -                       
  2953. -               case  'a':
  2954. -                       noabs++;
  2955. -                       goto  nx;
  2956. -
  2957. -               case  'R':
  2958. -               case  'N':
  2959. -                       if  (*arg == '\0')  {
  2960. -                               cnt++;
  2961. -                               arg = *++av;
  2962. -                               if  (arg == NULL)  {
  2963. -bo:                                    (void) fprintf(stderr,"Bad -%c option\n",lt);
  2964. -                                       exit(1);
  2965. -                               }
  2966. -                       }
  2967. -                       if  (lt == 'R')
  2968. -                               par_entry = ghex(arg);
  2969. -                       else
  2970. -                               par_round = ghex(arg) - 1;
  2971. -                       continue;
  2972. -                       
  2973. -               case  't':
  2974. -                       if  (*arg == '\0')  {
  2975. -                               cnt++;
  2976. -                               arg = *++av;
  2977. -                               if  (arg == NULL)
  2978. -                                       goto  bo;
  2979. -                       }
  2980. -                       tfnam = arg;
  2981. -                       continue;
  2982. -                       
  2983. -               case  'o':
  2984. -                       if  (*arg == '\0')  {
  2985. -                               cnt++;
  2986. -                               arg = *++av;
  2987. -                               if  (arg == NULL)
  2988. -                                       goto  bo;
  2989. -                      }
  2990. -                       if  (freopen(arg, "w", stdout) == NULL)  {
  2991. -                               (void) fprintf(stderr, "Help! cant open %s\n", arg);
  2992. -                               exit(20);
  2993. -                       }
  2994. -                       continue;
  2995. -               }
  2996. -       }
  2997. -}
  2998. -       
  2999. -/*
  3000. - *     Open binary files.  Arrange to erase them when finished.
  3001. - */
  3002. -
  3003. -void   bfopen(nam, fid)
  3004. -char   *nam;
  3005. -ef_fid fid;
  3006. -{
  3007. -       char    fnam[80];
  3008. -       
  3009. -       (void) sprintf(fnam, "%s.tx", nam);
  3010. -       if  ((fid->ef_t = open(fnam, O_RDWR|O_CREAT, 0666)) < 0)  {
  3011. -efil:          (void) fprintf(stderr, "Help could not open %s\n", fnam);
  3012. -               exit(4);
  3013. -       }
  3014. -       (void) unlink(fnam);
  3015. -       (void) sprintf(fnam, "%s.dt", nam);
  3016. -       if  ((fid->ef_d = open(fnam, O_RDWR|O_CREAT, 0666)) < 0)
  3017. -               goto  efil;
  3018. -       (void) unlink(fnam);
  3019. -}
  3020. -
  3021. -/*
  3022. - *     Close binary files.  They should get zapped anyway.
  3023. - */
  3024. -
  3025. -void   bfclose(fid)
  3026. -ef_fid fid;
  3027. -{
  3028. -       (void) close(fid->ef_t);
  3029. -       (void) close(fid->ef_d);
  3030. -}
  3031. -
  3032. -/*
  3033. - *     Main routine.
  3034. - */
  3035. -
  3036. -main(argc, argv)
  3037. -int    argc;
  3038. -char   *argv[];
  3039. -{
  3040. -       int     i;
  3041. -       char    *progname = argv[0];
  3042. -       char    *msg;
  3043. -       register  struct  libit  *lfd;
  3044. -       
  3045. -       i = doopts(argv);
  3046. -       argc -= i;
  3047. -       argv += i;
  3048. -       
  3049. -       if  (argc < 2)  {
  3050. -               (void) fprintf(stderr, "Usage: %s [ options ] file\n", progname);
  3051. -               exit(1);
  3052. -       }
  3053. -       
  3054. -       lfd = getfnam(argv[1]);
  3055. -       if  (lfd->lf_next > 0)  {
  3056. -               (void) fprintf(stderr, "Main file (%s) cannot be library\n", argv[1]);
  3057. -               exit(2);
  3058. -       }
  3059. -       
  3060. -       bfopen(tfnam, &mainfile);
  3061. -       if  (verbose)
  3062. -               (void) fprintf(stderr, "Scanning text\n");
  3063. -       if  (!rtext(lfd->lf_fd, lfd->lf_offset, &mainfile))  {
  3064. -               msg = "text";
  3065. -bf:            (void) fprintf(stderr, "Bad format input file -reading %s\n", msg);
  3066. -               exit(5);
  3067. -       }
  3068. -       if  (verbose)
  3069. -               (void) fprintf(stderr, "Scanning data\n");
  3070. -       if  (!rdata(lfd->lf_fd, lfd->lf_offset, &mainfile))  {
  3071. -               msg = "data";
  3072. -               goto  bf;
  3073. -       }
  3074. -       if  (verbose)
  3075. -               (void) fprintf(stderr, "Scanning symbols\n");
  3076. -       if  (!rsymb(lfd->lf_fd, lfd->lf_offset, dosymb, &mainfile))  {
  3077. -               msg = "symbols";
  3078. -               goto  bf;
  3079. -       }
  3080. -       if  (verbose)
  3081. -               (void) fprintf(stderr, "Scanning for relocation\n");
  3082. -       if  ((rel = rrel(lfd->lf_fd, lfd->lf_offset, &mainfile)) < 0)  {
  3083. -               msg = "reloc";
  3084. -               goto  bf;
  3085. -       }
  3086. -       
  3087. -       if  (rel)  {
  3088. -               if  (verbose)
  3089. -                       (void) fprintf(stderr, "File is relocatable\n");
  3090. -               if  (argc > 2)
  3091. -                       (void) fprintf(stderr, "Sorry - no scan on reloc files\n");
  3092. -       }
  3093. -       else
  3094. -               lscan(argc - 2, &argv[2]);
  3095. -
  3096. -       if  (verbose)
  3097. -               (void) fprintf(stderr, "End of input\n");
  3098. -       
  3099. -       (void) close(lfd->lf_fd);
  3100. -       if  (nmods > 0)
  3101. -               (void) fprintf(stderr, "Warning: at least %d merged modules\n",
  3102. -                       nmods + 1);
  3103. -
  3104. -       if  (mainfile.ef_stvec != NULL)  {
  3105. -               free(mainfile.ef_stvec);
  3106. -               mainfile.ef_stvec = NULL;
  3107. -               mainfile.ef_stcnt = 0;
  3108. -       }
  3109. -       
  3110. -       if  (verbose)
  3111. -               (void) fprintf(stderr, "Text anal 1\n");
  3112. -       intutext();
  3113. -       if  (verbose)
  3114. -               (void) fprintf(stderr, "Data anal 1\n");
  3115. -       intudat(&mainfile);
  3116. -       if  (!rel)  {
  3117. -               if  (verbose)
  3118. -                       (void) fprintf(stderr, "Data anal 2\n");
  3119. -               inturdat(&mainfile);
  3120. -       }
  3121. -       if  (lsyms)  {
  3122. -               if  (verbose)
  3123. -                       (void) fprintf(stderr, "Local symbol scan\n");
  3124. -              intlsym();
  3125. -       }
  3126. -       pabs();
  3127. -       ptext(&mainfile);
  3128. -       pdata(&mainfile);
  3129. -       pbss(&mainfile);
  3130. -       bfclose(&mainfile);
  3131. -       exit(0);
  3132. -}
  3133. //GO.SYSIN DD main.c
  3134. echo prin.c 1>&2
  3135. sed 's/.//' >prin.c <<'//GO.SYSIN DD prin.c'
  3136. -/*
  3137. - *     SCCS:   @(#)prin.c      1.2     11/2/84 14:19:47
  3138. - *     Print stuff.
  3139. - *
  3140. - ***********************************************************************
  3141. - *     This software is copyright of
  3142. - *
  3143. - *             John M Collins
  3144. - *             47 Cedarwood Drive
  3145. - *             St Albans
  3146. - *             Herts, AL4 0DN
  3147. - *             England                 +44 727 57267
  3148. - *
  3149. - *     and is released into the public domain on the following conditions:
  3150. - *
  3151. - *             1.  No free maintenance will be guaranteed.
  3152. - *             2.  Nothing may be based on this software without
  3153. - *                 acknowledgement, including incorporation of this
  3154. - *                 notice.
  3155. - *
  3156. - *     Notwithstanding the above, the author welcomes correspondence and bug
  3157. - *     fixes.
  3158. - ***********************************************************************
  3159. - */
  3160. -
  3161. -#include <stdio.h>
  3162. -#include <a.out.h>
  3163. -#include "unc.h"
  3164. -
  3165. -#define        LINELNG 70
  3166. -
  3167. -void   gette(), getde();
  3168. -long   gettw(), getdw();
  3169. -void   prinst();
  3170. -
  3171. -char   noabs;                  /*  No non-global absolutes  */
  3172. -int    rel;                    /*  File being analysed is relocatable  */
  3173. -int    lpos;
  3174. -
  3175. -struct commit  abstab, comtab;
  3176. -
  3177. -/*
  3178. - *     Print absolute and common values.
  3179. - */
  3180. -
  3181. -void   pabs()
  3182. -{
  3183. -       register  int   i;
  3184. -       register  symbol  cs;
  3185. -
  3186. -       for  (i = 0;  i < abstab.c_int;  i++)
  3187. -       
  3188. -       for  (i = 0;  i < abstab.c_int;  i++)  {
  3189. -               cs = abstab.c_symb[i];
  3190. -               if  (cs->s_glob)
  3191. -                       (void) printf("\t.globl\t%s\n", cs->s_name);
  3192. -               else  if  (noabs)
  3193. -                       continue;
  3194. -               (void) printf("%s\t=\t0x%lx\n", cs->s_name, cs->s_valu);
  3195. -       }
  3196. -       for  (i = 0;  i < comtab.c_int;  i++)  {
  3197. -               cs = comtab.c_symb[i];
  3198. -               (void) printf("\t.comm\t%s,%d\n", cs->s_name, cs->s_value);
  3199. -       }
  3200. -}
  3201. -
  3202. -/*
  3203. - *     Print out labels.
  3204. - */
  3205. -
  3206. -void   plabs(ls, seg)
  3207. -register  symbol  ls;
  3208. -int    seg;
  3209. -{
  3210. -       for  (; ls != NULL;  ls = ls->s_link)  {
  3211. -               if  (ls->s_type != seg)
  3212. -                       continue;
  3213. -               if  (ls->s_lsymb)  {
  3214. -                       (void) printf("%u$:\n", ls->s_lsymb);
  3215. -                       return;         /*  Set last  */
  3216. -               }
  3217. -               if  (ls->s_glob)
  3218. -                       (void) printf("\n\t.globl\t%s", ls->s_name);
  3219. -               (void) printf("\n%s:\n", ls->s_name);
  3220. -       }
  3221. -}
  3222. -
  3223. -/*
  3224. - *     Print out text.
  3225. - */
  3226. -
  3227. -void   ptext(fid)
  3228. -register  ef_fid  fid;
  3229. -{
  3230. -       register  long  tpos, endt;
  3231. -       t_entry tstr;
  3232. -
  3233. -       (void) printf(".text\n");
  3234. -       
  3235. -       tpos = fid->ef_tbase;
  3236. -       endt = tpos + fid->ef_tsize;
  3237. -contin:        
  3238. -       for  (;  tpos < endt;  tpos += tstr.t_lng * 2)  {
  3239. -               gette(fid, tpos, &tstr);
  3240. -               plabs(tstr.t_lab, TEXT);
  3241. -               if  (tstr.t_type == T_BEGIN)
  3242. -                       prinst(&tstr, tpos);
  3243. -               else  if  (tstr.t_relsymb != NULL)  {
  3244. -                       (void) printf("\t.long\t%s", tstr.t_relsymb->s_name);
  3245. -                       if  (tstr.t_relsymb->s_type!=TEXT &&
  3246. -                               tstr.t_relsymb->s_type!=DATA)
  3247. -                               (void) printf("+0x%x", gettw(fid, tpos, R_LONG));
  3248. -                       putchar('\n');
  3249. -                       tpos += 4;
  3250. -                       goto  contin;
  3251. -               }
  3252. -               else
  3253. -                       (void) printf("\t.word\t0x%x\n", tstr.t_contents);
  3254. -       }
  3255. -
  3256. -       /*
  3257. -        *      Print out any trailing label.
  3258. -        */
  3259. -       
  3260. -       gette(fid, tpos, &tstr);
  3261. -       plabs(tstr.t_lab, TEXT);
  3262. -}
  3263.  
  3264. -/*
  3265. - *     Print out data.
  3266. - */
  3267. -
  3268. -void   pdata(fid)
  3269. -register  ef_fid  fid;
  3270. -{
  3271. -       register  long  dpos, endd;
  3272. -       register  int   lng;
  3273. -       unsigned  ctyp;
  3274. -       int     had, par, inc;
  3275. -       char    *msg;
  3276. -       d_entry dstr;
  3277. -       
  3278. -       (void) printf("\n.data\n");
  3279. -       
  3280. -       dpos = fid->ef_dbase;
  3281. -       endd = dpos + fid->ef_dsize;
  3282. -
  3283. -       while  (dpos < endd)  {
  3284. -               
  3285. -               getde(fid, dpos, &dstr);
  3286. -               plabs(dstr.d_lab, DATA);
  3287. -                       
  3288. -               switch  (dstr.d_type)  {
  3289. -               case  D_CONT:
  3290. -                       (void) fprintf(stderr, "Data sync error\n");
  3291. -                       exit(200);
  3292. -                       
  3293. -               case  D_ASC:
  3294. -               case  D_ASCZ:
  3295. -                       ctyp = dstr.d_type;
  3296. -                       lng = dstr.d_lng;
  3297. -                       (void) printf("\t.asci");
  3298. -                       if  (ctyp == D_ASC)
  3299. -                               (void) printf("i\t\"");
  3300. -                       else  {
  3301. -                               (void) printf("z\t\"");
  3302. -                               lng--;
  3303. -                       }
  3304. -                               
  3305. -                       while  (lng > 0)  {
  3306. -                               getde(fid, dpos, &dstr);
  3307. -                               switch  (dstr.d_contents)  {
  3308. -                               default:
  3309. -                                       if  (dstr.d_contents < ' ' ||
  3310. -                                               dstr.d_contents > '~')
  3311. -                                               (void) printf("\\%.3o", dstr.d_contents);
  3312. -                                       else
  3313. -                                               putchar(dstr.d_contents);
  3314. -                                       break;
  3315. -                               case  '\"':
  3316. -                               case  '\'':
  3317. -                               case  '\\':
  3318. -                               case  '|':
  3319. -                                      (void) printf("\\%c", dstr.d_contents);
  3320. -                                       break;
  3321. -                               case  '\b':
  3322. -                                       (void) printf("\\b");
  3323. -                                       break;
  3324. -                               case  '\n':
  3325. -                                       (void) printf("\\n");
  3326. -                                       break;
  3327. -                               case  '\r':
  3328. -                                       (void) printf("\\r");
  3329. -                                       break;
  3330. -                               }
  3331. -                               
  3332. -                               lng--;
  3333. -                               dpos++;
  3334. -                       }
  3335. -                       (void) printf("\"\n");
  3336. -                       if  (ctyp == D_ASCZ)
  3337. -                               dpos++;
  3338. -                       break;
  3339. -
  3340. -               case  D_BYTE:
  3341. -                       msg = "byte";
  3342. -                       par = R_BYTE;
  3343. -                       inc = 1;
  3344. -                       goto  wrest;
  3345. -                       
  3346. -               case  D_WORD:
  3347. -                       msg = "word";
  3348. -                       par = R_WORD;
  3349. -                       inc = 2;
  3350. -                       goto  wrest;
  3351. -                       
  3352. -               case  D_LONG:
  3353. -                       msg = "long";
  3354. -                       par = R_LONG;
  3355. -                       inc = 4;
  3356. -               wrest:
  3357. -                       (void) printf("\t.%s\t", msg);
  3358. -                       lng = dstr.d_lng;
  3359. -                       lpos = 16;
  3360. -                       had = 0;
  3361. -                       while  (lng > 0)  {
  3362. -                               if  (lpos > LINELNG)  {
  3363. -                                       (void) printf("\n\t.%s\t", msg);
  3364. -                                       lpos = 16;
  3365. -                               }
  3366. -                               else  if  (had)
  3367. -                                       lpos += printf", ");
  3368. -
  3369. -                               lpos += printf("0x%x", getdw(fid, dpos, par));
  3370. -                               lng -= inc;
  3371. -                               dpos += inc;
  3372. -                               had++;
  3373. -                       }
  3374. -                       putchar('\n');
  3375. -                       break;
  3376. -
  3377. -               case  D_ADDR:
  3378. -                       (void) printf("\t.long\t");
  3379. -                       lng = dstr.d_lng;
  3380. -                       lpos = 16;
  3381. -                       had = 0;
  3382. -                       while  (lng > 0)  {
  3383. -                               if  (lpos > LINELNG)  {
  3384. -                                       (void) printf("\n\t.long\t");
  3385. -                                       lpos = 16;
  3386. -                               }
  3387. -                               else  if  (had)
  3388. -                                       lpos += printf(", ");
  3389. -
  3390. -                               getde(fid, dpos, &dstr);
  3391. -                               lpos += printf("%s", dstr.d_relsymb->s_name);
  3392. -                               lng -= sizeof(long);
  3393. -                               dpos += sizeof(long);
  3394. -                               had++;
  3395. -                       }
  3396. -                       putchar('\n');
  3397. -                       break;
  3398. -               }
  3399. -       }
  3400. -       
  3401. -       /*
  3402. -        *      Print trailing label.
  3403. -        */
  3404. -       
  3405. -       getde(fid, dpos, &dstr);
  3406. -       plabs(dstr.d_lab, DATA);
  3407. -}
  3408. -
  3409. -void   pbss(fid)
  3410. -register  ef_fid  fid;
  3411. -{
  3412. -       register  long  bpos = fid->ef_bbase;
  3413. -       long    endb = fid->ef_end;
  3414. -       d_entry bstr;
  3415. -       
  3416. -       (void) printf("\n.bss\n");
  3417. -       
  3418. -       while  (bpos < endb)  {
  3419. -               getde(fid, bpos, &bstr);
  3420. -               plabs(bstr.d_lab, BSS);
  3421. -               (void) printf("\t.space\t%d\n", bstr.d_lng);
  3422. -               bpos += bstr.d_lng;
  3423. -       }
  3424. -       
  3425. -       getde(fid, endb, &bstr);
  3426. -       plabs(bstr.d_lab, BSS);
  3427. -}
  3428. //GO.SYSIN DD prin.c
  3429. echo robj.c 1>&2
  3430. sed 's/.//' >robj.c <'//GO.SYSIN DD robj.c'
  3431. -/*
  3432. - *     SCCS:   @(#)robj.c      1.2     11/2/84 14:19:59
  3433. - *     Read object files.
  3434. - *
  3435. - ***********************************************************************
  3436. - *     This software is copyright of
  3437. - *
  3438. - *             John M Collins
  3439. - *             47 Cedarwood Drive
  3440. - *             St Albans
  3441. - *             Herts, AL4 0DN
  3442. - *             England                 +44 727 57267
  3443. - *
  3444. - *     and is released into the public domain on the following conditions:
  3445. - *
  3446. - *             1.  No free maintenance will be guaranteed.
  3447. - *             2.  Nothing may be based on this software without
  3448. - *                 acknowledgement, including incorporation of this
  3449. - *                 notice.
  3450. - *
  3451. - *     Notwithstanding the above, the author welcomes correspondence and bug
  3452. - *     fixes.
  3453. - ***********************************************************************
  3454. - *
  3455. - *     This particular module will obviously have to be munged beyond
  3456. - *     recognition for another object format.
  3457. - */
  3458. -
  3459. -#include <stdio.h>
  3460. -#include <a.out.h>
  3461. -#include "unc.h"
  3462. -
  3463. -void   gette(), getde(), setde(), putte(), putde();
  3464. -long   gettw(), getdw();
  3465. -void   reallst(), lclash(), nomem(), unimpl();
  3466. -void   addit();
  3467. -char   *malloc();
  3468. -long   lseek();
  3469. -
  3470. -int    par_entry, par_round, nmods, donedrel, donebrel;
  3471. -struct commit  abstab, comtab, dreltab;
  3472. -long   trelpos, drelpos, brelpos;
  3473. -
  3474. -ef_fids        mainfile;
  3475. -
  3476. -symbol lookup(), inventsymb(), getnsymb();
  3477. -
  3478. -#define        DBSIZE  100
  3479. -#define        STINIT  20
  3480. -
  3481. -/*
  3482. - *     Read text segment.  Return 0 if not ok.
  3483. - */
  3484. -
  3485. -int    rtext(inf, offset, outf)
  3486. -int    inf;            /*  a.out file (possibly in library)  */
  3487. -long   offset;         /*  Offset from start of inf of a.out file  */
  3488. -ef_fid outf;           /*  Output file descriptor  */
  3489. -{
  3490. -       t_entry         tstr;
  3491. -       struct  bhdr    filhdr;
  3492. -       register  long  size;
  3493. -       register  int   i, l;
  3494. -       unsigned  short inbuf[DBSIZE/2];
  3495. -
  3496. -      /*
  3497. -        *      Initialise fields in structure.
  3498. -        */
  3499. -       
  3500. -       tstr.t_type = T_UNKNOWN;
  3501. -       tstr.t_vins = 1;                /*  For the moment  */
  3502. -       tstr.t_bdest = 0;
  3503. -       tstr.t_gbdest = 0;
  3504. -       tstr.t_lng = 1;
  3505. -       tstr.t_reloc = R_NONE;
  3506. -       tstr.t_rdisp = 0;
  3507. -       tstr.t_isrel = 0;
  3508. -       tstr.t_amap = 0;
  3509. -       tstr.t_dref = 0;
  3510. -       tstr.t_relsymb = NULL;
  3511. -       tstr.t_reldisp = 0;
  3512. -       tstr.t_lab = NULL;
  3513. -       tstr.t_lsymb = 0;
  3514. -       tstr.t_refhi = 0;
  3515. -       tstr.t_reflo = 0x7fffffff;
  3516. -       tstr.t_match = 0;
  3517. -       
  3518. -       /*
  3519. -        *      Read a.out header.
  3520. -        */
  3521. -       
  3522. -       (void) lseek(inf, offset, 0);
  3523. -
  3524. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3525. -               return  0;
  3526. -
  3527. -       if  (filhdr.fmagic != FMAGIC  &&  filhdr.fmagic != NMAGIC)
  3528. -               return  0;
  3529. -
  3530. -       /*
  3531. -        *      Warn user if entry point does not tie up.
  3532. -        */
  3533. -       
  3534. -       if  (filhdr.entry != par_entry)
  3535. -               (void) fprintf(stderr, "Warning: File has -R%X\n", filhdr.entry);
  3536. -
  3537. -       outf->ef_entry = filhdr.entry;
  3538. -       outf->ef_tbase = filhdr.entry;
  3539. -       outf->ef_dbase = filhdr.tsize + filhdr.entry;
  3540. -
  3541. -       if  (filhdr.fmagic == NMAGIC)
  3542. -               outf->ef_dbase = (outf->ef_dbase + par_round) & (~par_round);
  3543. -
  3544. -       outf->ef_bbase = outf->ef_dbase + filhdr.dsize;
  3545. -       outf->ef_end = outf->ef_bbase + filhdr.bsize;
  3546. -
  3547. -       outf->ef_tsize = filhdr.tsize;
  3548. -       outf->ef_dsize = filhdr.dsize;
  3549. -       outf->ef_bsize = filhdr.bsize;
  3550. -       
  3551. -       (void) lseek(inf, offset + TEXTPOS, 0);
  3552. -       
  3553. -       size = outf->ef_tsize;
  3554. -       
  3555. -       while  (size > 1)  {
  3556. -               l = size > DBSIZE? DBSIZE: size;
  3557. -               if  (read(inf, (char *)inbuf, l) != l)
  3558. -                       return  0;
  3559. -               l /= 2;
  3560. -               for  (i = 0;  i < l;  i++)  {
  3561. -                       tstr.t_contents = inbuf[i];
  3562. -                       (void) write(outf->ef_t, (char *)&tstr, sizeof(tstr));
  3563. -               }
  3564. -               size -= l + l;
  3565. -       }
  3566. -       
  3567. -       /*
  3568. -        *      Extra one to cope with "etext".
  3569. -        */
  3570. -       
  3571. -       (void) write(outf->ef_t, (char *)&tstr, sizeof(tstr));
  3572. -       return  1;
  3573. -}
  3574. -
  3575. -/*
  3576. - *     Same sort of thing for the data segment.
  3577. - */
  3578. -
  3579. -int    rdata(inf, offset, outf)
  3580. -int    inf;            /*  a.out file (possibly in library)  */
  3581. -long   offset;         /*  Offset from start of inf of a.out file  */
  3582. -ef_fid outf;           /*  Output file descriptor  */
  3583. -{
  3584. -       d_entry         dstr;
  3585. -       struct  bhdr    filhdr;
  3586. -       register  long  size;
  3587. -       register  int   i, l;
  3588. -       unsigned  char  inbuf[DBSIZE];
  3589. -
  3590. -       /*
  3591. -        *      Initialise fields in structure.
  3592. -        */
  3593. -       
  3594. -       dstr.d_type = D_BYTE;
  3595. -       dstr.d_reloc = R_NONE;
  3596. -       dstr.d_lng = 1;
  3597. -       dstr.d_relsymb = NULL;
  3598. -       dstr.d_reldisp = 0;
  3599. -       dstr.d_lab = NULL;
  3600. -       
  3601. -       /*
  3602. -        *      Read a.out header.
  3603. -        */
  3604. -       
  3605. -       (void) lseek(inf, offset, 0);
  3606. -
  3607. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3608. -               return  0;
  3609. -
  3610. -       (void) lseek(inf, offset + DATAPOS, 0);
  3611. -       
  3612. -       size = outf->ef_dsize;
  3613. -       
  3614. -       while  (size > 0)  {
  3615. -               l = size > DBSIZE? DBSIZE: size;
  3616. -               if  (read(inf, (char *)inbuf, l) != l)
  3617. -                       return  0;
  3618. -               for  (i = 0;  i < l;  i++)  {
  3619. -                       dstr.d_contents = inbuf[i];
  3620. -                       (void) write(outf->ef_d, (char *)&dstr, sizeof(dstr));
  3621. -               }
  3622. -               size -= l;
  3623. -       }
  3624. -       
  3625. -       /*
  3626. -        *      Repeat for BSS segment.
  3627. -        */
  3628. -
  3629. -       dstr.d_contents = 0;
  3630. -       for  (size = outf->ef_bsize;  size > 0;  size--)
  3631. -               (void) write(outf->ef_d, (char *)&dstr, sizeof(dstr));
  3632. -       
  3633. -      /*
  3634. -        *      Extra one to cope with "end".
  3635. -        */
  3636. -       
  3637. -       (void) write(outf->ef_d, (char *)&dstr, sizeof(dstr));
  3638. -       return  1;
  3639. -}
  3640. -
  3641. -/*
  3642. - *     Process symbol table segment.
  3643. - */
  3644. -
  3645. -int    rsymb(inf, offset, dproc, outf)
  3646. -int    inf;            /*  a.out file (possibly in library)  */
  3647. -long   offset;         /*  Offset from start of inf of a.out file  */
  3648. -symbol (*dproc)();
  3649. -register  ef_fid  outf;        /*  Output file descriptor  */
  3650. -{
  3651. -       register  symbol  csym;
  3652. -       struct  bhdr    filhdr;
  3653. -       struct  sym     isym;
  3654. -       register  long  size;
  3655. -       register  int   i, l;
  3656. -       char    inbuf[SYMLENGTH+1];
  3657. -
  3658. -       /*
  3659. -        *      Read a.out header.
  3660. -        */
  3661. -       
  3662. -       (void) lseek(inf, offset, 0);
  3663. -
  3664. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3665. -               return  0;
  3666. -
  3667. -       offset += SYMPOS;
  3668. -       size = filhdr.ssize;
  3669. -       if  (size <= 0)
  3670. -               return  1;
  3671. -
  3672. -       /*
  3673. -        *      Guesstimate symbol table vector size.
  3674. -        */
  3675. -
  3676. -       l = size / (sizeof(struct sym) + 4);
  3677. -       if  (l <= 0)
  3678. -               l = STINIT;
  3679. -
  3680. -       outf->ef_stvec = (symbol *) malloc(l * sizeof(symbol));
  3681. -       if  (outf->ef_stvec == NULL)
  3682. -               nomem();
  3683. -
  3684. -       outf->ef_stcnt = 0;
  3685. -       outf->ef_stmax = l;
  3686. -       
  3687. -       while  (size > sizeof(struct sym))  {
  3688. -               (void) lseek(inf, offset, 0);
  3689. -               if  (read(inf, (char *)&isym, sizeof(isym)) != sizeof(isym))
  3690. -                       return  0;
  3691. -               size -= sizeof(isym);
  3692. -               l = SYMLENGTH;
  3693. -               if  (l > size)
  3694. -                       l = size;
  3695. -               if  (read(inf, inbuf, l) != l)
  3696. -                       return  0;
  3697. -               inbuf[l] = '\0';
  3698. -               for  (i = 0; inbuf[i] != '\0';  i++)
  3699. -                       ;
  3700. -               size -= i + 1;
  3701. -               offset += sizeof(isym) + i + 1;
  3702. -               csm = (*dproc)(lookup(inbuf), isym.stype, isym.svalue, outf);
  3703. -               if  (outf->ef_stcnt >= outf->ef_stmax)
  3704. -                       reallst(outf);
  3705. -               outf->ef_stvec[outf->ef_stcnt++] = csym;
  3706. -       }
  3707. -       return  1;
  3708. -}
  3709. -
  3710. -/*
  3711. - *     Process relocation stuff.  -1 error, 0 no relocation, 1 relocation.
  3712. - */
  3713. -
  3714. -int    rrel(inf, offset, outf)
  3715. -int    inf;            /*  a.out file (possibly in library)  */
  3716. -long   offset;         /*  Offset from start of inf of a.out file  */
  3717. -ef_fid outf;           /*  Output file descriptor  */
  3718. -{
  3719. -       struct  bhdr    filhdr;
  3720. -       struct  reloc   crel;
  3721. -       t_entry tstr;
  3722. -       d_entry dstr;
  3723. -       register  long  size;
  3724. -       long    cont, pos;
  3725. -
  3726. -       /*
  3727. -        *      Read a.out header.
  3728. -        */
  3729. -       
  3730. -       (void) lseek(inf, offset, 0);
  3731. -
  3732. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3733. -               return  -1;
  3734. -       if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  3735. -               return  0;
  3736. -
  3737. -       size  =  filhdr.rtsize;
  3738. -
  3739. -       (void) lseek(inf, RTEXTPOS + offset, 0);
  3740. -       while  (size >= sizeof(struct reloc))  {
  3741. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  3742. -                       return  -1;
  3743. -
  3744. -               pos = crel.rpos + outf->ef_tbase;
  3745. -               gette(outf, pos, &tstr);
  3746. -               tstr.t_reloc = crel.rsize + 1;  /*  Fiddle!  YUK!!!  */
  3747. -               tstr.t_rdisp = crel.rdisp;
  3748. -               tstr.t_rptr = crel.rsegment;
  3749. -               if  (crel.rsegment == REXT)  {
  3750. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  3751. -                               return  -1;
  3752. -                       tstr.t_relsymb = outf->ef_stvec[crel.rsymbol];
  3753. -                       tstr.t_reldisp = gettw(outf, pos, (int)crel.rsize+1);
  3754. -               }
  3755. -               else  {
  3756. -                       cont = gettw(outf, pos, (int)crel.rsize+1);
  3757. -                       tstr.t_relsymb = getnsymb(outf, crel.rsegent, cont);
  3758. -               }
  3759. -               tstr.t_relsymb->s_used++;
  3760. -               putte(outf, pos, &tstr);
  3761. -               size -= sizeof(crel);
  3762. -       }
  3763. -       
  3764. -       /*
  3765. -        *      And now repeat all that for data relocations.
  3766. -        */
  3767. -       
  3768. -       size  =  filhdr.rdsize;
  3769. -       
  3770. -       (void) lseek(inf, RDATAPOS + offset, 0);
  3771. -       while  (size >= sizeof(struct reloc))  {
  3772. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  3773. -                       return  -1;
  3774. -
  3775. -               pos = crel.rpos + outf->ef_dbase;
  3776. -               getde(outf, pos, &dstr);
  3777. -               dstr.d_reloc = crel.rsize + 1;  /*  Fiddle!  YUK!!!  */
  3778. -               dstr.d_rptr = crel.rsegment;
  3779. -
  3780. -               if  (crel.rsegment == REXT)  {
  3781. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  3782. -                               return  -1;
  3783. -                       dstr.d_relsymb = outf->ef_stvec[crel.rsymbol];
  3784. -                       dstr.d_reldisp = getdw(outf, pos, (int)crel.rsize+1);
  3785. -               }
  3786. -               else  {
  3787. -                       cont = getdw(outf, pos, (int)crel.rsize+1);
  3788. -                       dstr.d_relsymb = getnsymb(outf, crel.rsegment, cont);
  3789. -                       if  (dstr.d_relsymb->s_type == TEXT)  {
  3790. -                               gette(outf, cont, &tstr);
  3791. -                               tstr.t_dref = 1;
  3792. -                               putte(outf, cont, &tstr);
  3793. -                       }
  3794. -               }
  3795. -               switch  (crel.rsize)  {
  3796. -               default:
  3797. -                       unimpl("Data byte relocation");
  3798. -                       break;
  3799. -               case  RWORD:
  3800. -                       unimpl("data word reloc");
  3801. -                       dstr.d_type = D_WORD;
  3802. -                       dstr.d_lng = 2;
  3803. -                       setde(outf, pos+1, D_CONT, 1);
  3804. -                       break;
  3805. -               case  RLONG:
  3806. -                       dstr.d_type = D_ADDR;
  3807. -                       dstr._lng = 4;
  3808. -                       setde(outf, pos+1, D_CONT, 1);
  3809. -                       setde(outf, pos+2, D_CONT, 1);
  3810. -                       setde(outf, pos+3, D_CONT, 1);
  3811. -                       break;
  3812. -               }
  3813. -               dstr.d_relsymb->s_used++;
  3814. -               putde(outf, pos, &dstr);
  3815. -               size -= sizeof(crel);
  3816. -       }
  3817. -       return 1;
  3818. -}
  3819. -
  3820. -/*
  3821. - *     Process a symbol.
  3822. - */
  3823. -
  3824. -symbol dosymb(sy, type, val, fid)
  3825. -register  symbol  sy;
  3826. -int    type;
  3827. -long   val;
  3828. -ef_fid fid;
  3829. -{
  3830. -       t_entry tstr;
  3831. -       d_entry dstr;
  3832. -       
  3833. -       if  (!sy->s_newsym)  {
  3834. -               if  (type & EXTERN)  {
  3835. -                       (void) fprintf(stderr, "Duplicate symbol %s\n", sy->s_name);
  3836. -                       exit(10);
  3837. -               }
  3838. -               if  (++sy->s_defs > nmods)
  3839. -                       nmods = sy->s_defs;
  3840. -               sy = inventsymb("DUP");
  3841. -       }
  3842. -
  3843. -       sy->s_value = val;
  3844. -       
  3845. -       switch  (type)  {
  3846. -       default:
  3847. -               return  NULL;
  3848. -               
  3849. -       case  EXTERN|UNDEF:
  3850. -               if  (val != 0)  {
  3851. -                       sy->s_type = COMM;
  3852. -                       addit(&comtab, sy);
  3853. -               }
  3854. -               else
  3855. -                       sy->s_type = N_UNDF;
  3856. -               sy->s_glob = 1;
  3857. -               break;
  3858. -               
  3859. -       case  EXTERN|ABS:
  3860. -               sy->s_type = N_ABS;
  3861. -               sy->s_glob = 1;
  3862. -               addit(&abstab, sy);
  3863. -               break;
  3864. -               
  3865. -       case  ABS:
  3866. -               sy->s_type = N_ABS;
  3867. -               addit(&abstab, sy);
  3868. -               break;
  3869. -               
  3870. -       case  EXTERN|TEXT:
  3871. -       case  TEXT:
  3872. -               sy->s_type = N_TEXT;
  3873. -               gette(fid, val, &tstr);
  3874. -               tstr.t_bdest = 1;
  3875. -               if  (type & EXTERN)  {
  3876. -                       tstr.t_gbdest = 1;
  3877. -                       sy->s_glob = 1;
  3878. -               }
  3879. -               sy->s_link = tsr.t_lab;
  3880. -               tstr.t_lab = sy;
  3881. -               putte(fid, val, &tstr);
  3882. -               break;
  3883. -               
  3884. -       case  BSS:
  3885. -       case  EXTERN|BSS:
  3886. -               sy->s_type = N_BSS;
  3887. -               goto    datrest;
  3888. -       case  DATA:
  3889. -       case  EXTERN|DATA:
  3890. -               sy->s_type = N_DATA;
  3891. -       datrest:
  3892. -               getde(fid, val, &dstr);
  3893. -               if  (type & EXTERN)
  3894. -                       sy->s_glob = 1;
  3895. -               sy->s_link = dstr.d_lab;
  3896. -               dstr.d_lab = sy;
  3897. -               putde(fid, val, &dstr);
  3898. -               break;
  3899. -       }
  3900. -       
  3901. -       sy->s_newsym = 0;
  3902. -       return  sy;
  3903. -}
  3904. -
  3905. -/*
  3906. - *     Process relocation stuff in putative library modules.
  3907. - *     The main function of all this is to mark which bits of the text
  3908. - *     not to look at as I compare the stuff.
  3909. - *
  3910. - *     As with "rrel", return -1 error, 0 no relocation, 1 relocation.
  3911. - */
  3912. -
  3913. -int    rrell1(inf, offset, outf)
  3914. -int    inf;            /*  a.out file (possibly in library)  */
  3915. -long   offset;         /*  Offset from start of inf of a.out file  */
  3916. -ef_fid outf;           /*  Output file descriptor  */
  3917. -{
  3918. -       struct  bhdr    filhdr;
  3919. -       struct  reloc   crel;
  3920. -       t_entry tstr;
  3921. -       register  long  size;
  3922. -       long    pos;
  3923. -
  3924. -       /*
  3925. -        *      Read a.out header.
  3926. -        */
  3927. -       
  3928. -       (void) lseek(inf, offset, 0);
  3929. -
  3930. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3931. -               return  -1;
  3932. -       if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  3933. -               return  0;
  3934. -
  3935. -       size  =  filhdr.rtsize;
  3936. -
  3937. -       (void) lseek(inf, RTEXTPOS + offset, 0);
  3938. -       while  (size >= sizeof(struct reloc))  {
  3939. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  3940. -                       return  -1;
  3941. -
  3942. -               pos = crel.rpos + outf->ef_tbase;
  3943. -               gette(outf, pos, &tstr);
  3944. -               tstr.t_reloc = crel.rsize + 1;  /*  Fidde!  YUK!!!  */
  3945. -               tstr.t_rdisp = crel.rdisp;
  3946. -               tstr.t_rptr = crel.rsegment;
  3947. -               tstr.t_isrel = 1;
  3948. -               putte(outf, pos, &tstr);
  3949. -               if  (crel.rsize == RLONG)  {
  3950. -                       gette(outf, pos+2, &tstr);
  3951. -                       tstr.t_isrel = 1;
  3952. -                       putte(outf, pos+2, &tstr);
  3953. -               }
  3954. -               size -= sizeof(crel);
  3955. -       }
  3956. -       
  3957. -       /*
  3958. -        *      Dont bother with data relocation at this stage. We'll
  3959. -        *      tie that up later.
  3960. -        */
  3961. -       
  3962. -       return 1;
  3963. -}
  3964. -
  3965. -/*
  3966. - *     Process a symbol in library file.  The extern variable trelpos gives
  3967. - *     the place in the main file where the library module is relocated.
  3968. - *     We don't know the data position until we do the final merge, perhaps
  3969. - *     not even then.
  3970. - */
  3971. -
  3972. -symbol dolsymb(sy, type, val, fid)
  3973. -register  symbol  sy;
  3974. -int    type;
  3975. -long   val;
  3976. -ef_fid fid;
  3977. -{
  3978. -       t_entry tstr;
  3979. -       
  3980. -       switch  (type)  {
  3981. -       default:
  3982. -               return  NULL;
  3983. -               
  3984. -       case  EXTERN|UNDEF:
  3985. -               if  (!sy->s_newsym)
  3986. -                       return  sy;
  3987. -               sy->s_value = val;
  3988. -               if  (val != 0)  {
  3989. -                       sy->s_type = COMM;
  3990. -                       addit(&dreltab, sy);
  3991. -               }
  3992. -               else
  3993. -                       sy->s_type = N_UNDF;
  3994. -               sy->s_glob = 1;
  3995. -               break;
  3996. -               
  3997. -       case  EXTERN|ABS:
  3998. -               if  (!sy->s_newsym)  {
  3999. -                       if  (sy->s_type != N_ABS || sy->s_value != val)
  4000. -                               lclash("abs");
  4001. -               }
  4002. -               sy->s_type = N_ABS;
  4003. -               sy->s_value = val;
  4004. -               sy->s_glob = 1;
  4005. -               addit(&abstab, sy);
  4006. -               break;
  4007. -               
  4008. -       case  EXTERN|TEXT:
  4009. -               sy->s_type = N_TEXT;
  4010. -               val += trelpos - fid-ef_tbase;
  4011. -               if  (!sy->s_newsym)  {
  4012. -                       if  (val != sy->s_value)
  4013. -                               lclash("tsym");
  4014. -                       return  sy;
  4015. -               }
  4016. -               sy->s_value = val;
  4017. -               gette(&mainfile, val, &tstr);
  4018. -               tstr.t_bdest = 1;
  4019. -               tstr.t_gbdest = 1;
  4020. -               sy->s_glob = 1;
  4021. -               sy->s_link = tstr.t_lab;
  4022. -               tstr.t_lab = sy;
  4023. -               putte(&mainfile, val, &tstr);
  4024. -               break;
  4025. -
  4026. -       case  EXTERN|BSS:
  4027. -               if  (!sy->s_newsym)
  4028. -                       return  sy;
  4029. -               sy->s_type = N_BSS;
  4030. -               sy->s_value = val - fid->ef_bbase;
  4031. -               goto    datrest;
  4032. -
  4033. -       case  EXTERN|DATA:
  4034. -               if  (!sy->s_newsym)
  4035. -                       return  sy;
  4036. -               sy->s_type = N_DATA;
  4037. -               sy->s_value = val - fid->ef_dbase;
  4038. -       datrest:
  4039. -               sy->s_glob = 1;
  4040. -               addit(&dreltab, sy);
  4041. -               break;
  4042. -       }
  4043. -       
  4044. -       sy->s_newsym = 0;
  4045. -       return  sy;
  4046. -}
  4047. -
  4048. -/*
  4049. - *     Change definition of undefined symbol as we define it.
  4050. - */
  4051. -
  4052. -void   reassign(sy, val)
  4053. -register  symbol  sy;
  4054. -long   val;
  4055. -{
  4056. -       sy->s_value = val;
  4057. -
  4058. -       if  (val < mainfile.ef_tbase)  {
  4059. -               sy->s_type = N_ABS;
  4060. -               addit(&abstab, sy);
  4061. -       }
  4062. -       else  if  (val < mainfile.ef_dbase)  {
  4063. -               t_entry tstr;
  4064. -               
  4065. -               sy->s_type = N_TEXT;
  4066. -               gette(&mainfile, val, &tstr);
  4067. -               tstr.t_bdest = 1;
  4068. -               tstr.t_gbdest = 1;
  4069. -               sy->s_glob = 1;
  4070. -               sy->s_link = tstr.t_lab;
  4071. -               tstr.t_lab = sy;
  4072. -               putte(&mainfile, val, &tstr);
  4073. -       }
  4074. -       else  {
  4075. -               d_entry dstr;
  4076. -               
  4077. -               sy->s_type = val < mainfile.ef_bbase? N_DATA: N_BSS;
  4078. -               getde(&mainfile, val &dstr);
  4079. -               sy->s_link = dstr.d_lab;
  4080. -               dstr.d_lab = sy;
  4081. -               putde(&mainfile, val, &dstr);
  4082. -       }
  4083. -}
  4084. -
  4085. -/*
  4086. - *     When we discover where bss or data come, reallocate the table.
  4087. - */
  4088. -
  4089. -void   zapdat(seg, inc)
  4090. -int    seg;
  4091. -long   inc;
  4092. -{
  4093. -       register  int   i;
  4094. -       register  symbol  csymb;
  4095. -       d_entry dent;
  4096. -       
  4097. -       for  (i = 0;  i < dreltab.c_int;  i++) {
  4098. -               csymb = dreltab.c_symb[i];
  4099. -               if  (csymb->s_type != seg)
  4100. -                       continue;
  4101. -               csymb->s_value += inc;
  4102. -               getde(&mainfile, csymb->s_value, &dent);
  4103. -               csymb->s_link = dent.d_lab;
  4104. -               dent.d_lab = csymb;
  4105. -               putde(&mainfile, csymb->s_value, &dent);
  4106. -       }
  4107. -}
  4108. -
  4109. -/*
  4110. - *     Process relocation stuff in library module which we are inserting.
  4111. - *     Horrors if something goes wrong.
  4112. - */
  4113. -
  4114. -void   rrell2(inf, offset, outf)
  4115. -int    inf;            /*  a.out file (possibly in library)  */
  4116. -long   offset;         /*  Offset from start of inf of a.out file  */
  4117. -ef_fid outf;           /*  Output file descriptor  */
  4118. -{
  4119. -       struct  bhdr    filhdr;
  4120. -       struct  reloc   crel;
  4121. -       t_entry mtstr;
  4122. -       d_entry mdstr;
  4123. -       register  long  size;
  4124. -       register  symbol  csymb;
  4125. -       long    pos, mpos, mval, lval;
  4126. -       int     dhere = 0;              /*  Mark whether bss done  */
  4127. -
  4128. -       /*
  4129. -        *      Read a.out header.
  4130. -        */
  4131. -       
  4132. -       (void) lseek(inf, offset, 0);
  4133. -
  4134. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  4135. -               return;
  4136. -       if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  4137. -               return;
  4138. -
  4139. -       size  =  filhdr.rtsize;
  4140. -
  4141. -       (void) lseek(inf, RTEXTPOS + offset, 0);
  4142. -       for  (;  size >= sizeof(struct reloc);  size -= sizeof(crel))  {
  4143. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  4144. -                       lclash("rd rel");
  4145. -
  4146. -               pos = crel.rpos + outf->ef_tbase;
  4147. -               mpos = crel.rpos + trelpos;
  4148. -               gette(&mainfile, mpos, &mtstr);
  4149. -               lval = gettw(outf, pos, (int)crel.rsize+1);
  4150. -               mval = gettw(&mainfile, mpos, (int)crel.rsize+1);
  4151. -               
  4152. -               switch  (crel.rsegment)  {
  4153. -               case  RTEXT:
  4154. -                       if  (lval + trelpos - outf->ef_tbase != mval)
  4155. -                               lclash("Trel");
  4156. -                       continue;
  4157. -               case  RDATA:
  4158. -                       if  (donedrel)  {
  4159. -                               if  (lval + drelpos - outf->ef_dbase != mval)
  4160. -                                       lclash("Drel");
  4161. -                       }
  4162. -                       else  {
  4163. -                               donedrel++;
  4164. -                               drelpos = mval - lval + outf->ef_dbase;
  4165. -                       }
  4166. -                       continue;
  4167. -               case  RBSS:
  4168. -                       if  (donebrel)  {
  4169. -                               if  (lval + brelpos - outf->ef_bbase != mval)
  4170. -                                       lclash("brel");
  4171. -                       }
  4172. -                       else  {
  4173. -                               donebrel++;
  4174. -                               brelpos = mval - lval + outf->ef_bbase;
  4175. -                       }
  4176. -                       continue;
  4177. -               case  REXT:
  4178. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  4179. -                               lclash("Bad sy no");
  4180. -                       csymb = outf->ef_stvec[crel.rsymbol];
  4181. -                       if  (csymb == NULL)
  4182. -                               continue;
  4183. -                       switch  (csymb->s_type)  {
  4184. -                       case  N_UNDF:
  4185. -                               reassign(csymb, mval - lval);
  4186. -                               break;
  4187. -                       case  N_ABS:
  4188. -                               if  (lval + csymb->s_value != mval)
  4189. -                                      lclash("abs rel");
  4190. -                               break;
  4191. -                       case  N_TEXT:
  4192. -                               if  (lval + csymb->s_value != mval)
  4193. -                                       lclash("text rel");
  4194. -                               break;
  4195. -                       case  N_DATA:
  4196. -                               if  (lval + csymb->s_value != mval)
  4197. -                                       lclash("data rel");
  4198. -                               break;
  4199. -                       case  N_BSS:
  4200. -                               if  (lval + csymb->s_value != mval)
  4201. -                                       lclash("bss rel");
  4202. -                               break;
  4203. -                       case  COMM:
  4204. -                               reassign(csymb, mval - lval);
  4205. -                               break;
  4206. -                       }
  4207. -                       mtstr.t_relsymb = csymb;
  4208. -                       mtstr.t_reldisp = lval;
  4209. -                       break;
  4210. -               }
  4211. -       }
  4212. -       
  4213. -       /*
  4214. -        *      Relocate data and bss if possible.
  4215. -        */
  4216. -       
  4217. -       if  (donebrel)  {
  4218. -               zapdat(N_BSS, brelpos);
  4219. -               dhere++;
  4220. -       }
  4221. -       
  4222. -       if  (!donedrel)
  4223. -               return;
  4224. -               
  4225. -
  4226. -       zapdat(N_DATA, drelpos);
  4227. -       
  4228. -       /*
  4229. -        *      And now repeat all that for data relocations if possible
  4230. -        */
  4231. -       
  4232. -       size  =  filhdr.rdsize;
  4233. -       
  4234. -       (void) lseek(inf, RDATAPOS + offset, 0);
  4235. -       for  (;  size >= sizeof(struct reloc); size -= sizeof(crel))  {
  4236. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  4237. -                       lclash("Rd drel");
  4238. -
  4239. -               if  (crel.rsize != RLONG)
  4240. -                       continue;
  4241. -
  4242. -               pos = crel.rpos + outf->ef_dbase;
  4243. -               mpos = crel.rpos + drelpos;
  4244. -               getde(&mainfile, mpos, &mdstr);
  4245. -               lval = getdw(outf, pos, (int)crel.rsize+1);
  4246. -              mval = getdw(&mainfile, mpos, (int)crel.rsize+1);
  4247. -               switch  (crel.rsegment)  {
  4248. -               case  RTEXT:
  4249. -                       if  (lval + trelpos - outf->ef_tbase != mval)
  4250. -                               lclash("Trel-d");
  4251. -                       continue;
  4252. -               case  RDATA:
  4253. -                       if  (lval + drelpos - outf->ef_dbase != mval)
  4254. -                               lclash("Drel-d");
  4255. -                       continue;
  4256. -               case  RBSS:
  4257. -                       if  (donebrel)  {
  4258. -                               if  (lval + brelpos - outf->ef_bbase != mval)
  4259. -                                       lclash("brel");
  4260. -                       }
  4261. -                       else  {
  4262. -                               donebrel++;
  4263. -                               brelpos = mval - lval + outf->ef_bbase;
  4264. -                       }
  4265. -                       continue;
  4266. -               case  REXT:
  4267. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  4268. -                               lclash("Bad sy no");
  4269. -                       csymb = outf->ef_stvec[crel.rsymbol];
  4270. -                       if  (csymb == NULL)
  4271. -                               continue;
  4272. -                       switch  (csymb->s_type)  {
  4273. -                       case  N_UNDF:
  4274. -                               reassign(csymb, mval - lval);
  4275. -                               break;
  4276. -                       case  N_ABS:
  4277. -                               if  (lval + csymb->s_value != mval)
  4278. -                                       lclash("abs rel");
  4279. -                               break;
  4280. -                       case  N_TEXT:
  4281. -                               if  (lval + csymb->s_value != mval)
  4282. -                                       lclash("text rel");
  4283. -                               break;
  4284. -                       case  N_DATA:
  4285. -                               if  (lval + csymb->s_value != mval)
  4286. -                                       lclash("data rel");
  4287. -                               break;
  4288. -                      case  N_BSS:
  4289. -                               if  (lval + csymb->s_value != mval)
  4290. -                                       lclash("bss rel");
  4291. -                               break;
  4292. -                       case  COMM:
  4293. -                               reassign(csymb, mval - lval);
  4294. -                               break;
  4295. -                       }
  4296. -                       mtstr.t_relsymb = csymb;
  4297. -                       mtstr.t_reldisp = lval;
  4298. -                       break;
  4299. -               }
  4300. -       }
  4301. -
  4302. -       if  (dhere || !donebrel)
  4303. -               return;
  4304. -
  4305. -       zapdat(N_BSS, brelpos);
  4306. -}
  4307. //GO.SYSIN DD robj.c
  4308. -- 
  4309. John M Collins          ....mcvax!ist!inset!jmc
  4310. Phone:  +44 727 57267
  4311. Snail Mail: 47 Cedarwood Drive, St Albans, Herts, AL4 0DN, England.
  4312.                          brelpos = mval - lval + outf->ef_bbase;
  4313. -                       }
  4314. -